📄 invvarargs.20010527.html
字号:
<html><!-- Mirrored from c-faq.com/varargs/invvarargs.20010527.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 08:03:12 GMT --><head><title>"inverse varargs problem", take 10</title></head><body>[This message was originally sent on May 27, 2001,to someone who was asking about constructing variable-length argument lists.I have edited the text slightly for this web page.]<p>From: scs@eskimo.com (Steve Summit)<br>Date: Sun, 27 May 2001 10:49:32 -0500<br>Message-Id: <2001May27.1049.scs.009@aeroroot.scs.ndip.eskimo.net><br>Subject: Re: Variable Argument lists in C<p>You wrote:<br>> Hi, I was searching on Google for a way to build a variable of type<br>> va_list. My task is to accept a variable number of parameters with<br>> one function, remove a few arguments from that list, and then pass the<br>> va_list to another function, probably vprintf or vsprintf...<br>> Do you know how this could be accomplished? I either need<br>> to simply remove the args from the va_list that I obtain from the<br>> first function call, or build a new va_list and omit the unwanted args.<p>Well, there are two very different answers to this question.The first is that there is no portable way of doing this sortof thing at all; the "solutions" all involve either assemblylanguage or ghastly kludges, or both. If at all possible, youshould find some other way of accomplishing your higher taskthat doesn't involve trying to build or manipulate argument listson the fly. Getting involved with dynamic argument lists isa lot like getting involved with absinthe: darkly exotic andstimulating at first, but destructive and mind-rotting in theend.<p>That's the sober, responsible answer. The second answer is thatdynamic function calls <em>are</em> exotic and stimulating and tons offun. But they're not easy; they <em>do</em> require either assemblylanguage or ghastly kludges (or both). This is what <a href="invvarargs.html">question15.13</a> in the <a href="http://www.eskimo.com/~scs/C-faq/top.html">comp.lang.c FAQ list</a> is about; I'm appending my<a href="http://www.eskimo.com/notfound.html">collection of "wacky ideas"</a> at the end of this message. Besidesthe ideas there, lately I've been having mostly good luck with aset of gcc extensions: <TT>__builtin_apply_args</TT>, <TT>__builtin_apply</TT>, and<TT>__builtin_return</TT>. (I can't tell you how to use these, becauseI barely understand them myself, but if you're using gcc, theymight be an option for you. The only documentation I know offor them is the gcc Info node "Constructing Calls".)<p><address><a href="http://www.eskimo.com/~scs/">Steve Summit</a><br><a href="mailto:scs@eskimo.com">scs@eskimo.com</a></address></body><!-- Mirrored from c-faq.com/varargs/invvarargs.20010527.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 08:03:13 GMT --></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -