This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Passing va_args...




Dave Korn wrote:
On 09 March 2006 13:11, Jean-Yves Bitterlich wrote:

  Jean, do you know you're replying to an email from October 2005?  Ah well, I
see the thread ended without all the information coming out, Andreas said it
was impossible but didn't go into the details so it's worth mentioning the
builtins.

Kalaky <kalaky@gmail.com> writes:

 > I'am looking for some way to pass variable arguments to another
 > function that receives variable arguments without using va_list.

This is impossible.
what about?
#define DOTS ...

function_1 (int z, ...);
function_2 (int z, ...);
{
   return function_1 (z, DOTS);
}



Why would substituting a macro for '...' suddenly make the nonsense statement

return function_1 (z, ...);

mean anything? That won't even compile, let alone do what you want.

well ... it does compile (2.95.3)


aim is easy to find (function_2 is public method doing a bit known (i.e. "z" argument pre-checking), whereas function_1 is internal (of a library for example)). ... also I have to admit, a macro() is probably the best choice in most case.


It may be impossible in practice, but it is supposed to be possible to do this, depsite what Andreas Schwab wrote two messages (and five months) upthread. Gcc has some functions such as __builtin_apply_args, __builtin_apply and __builtin_return that let you attempt this, but they are very tricky features to get right and may fail on some platforms or in some corner cases. See the gcc manual section on constructing function calls, at

a question concerning the __builtin_* functions: could these functions help me in finding out whether there are at lease 1 argument passed ?
The background is the following constructs:


function b(q,w,f,va_list a) {
....
}

function a(x,f,...) {
va_list a;
va_start(a,f);
b(q,w,f,a);
va_end(a)
}

How can check in function b that there is at least 1 parameter ?
i.e. How can I avoid such things like a(x,"%s") => b(q,w,"%s",a)


cheers, DaveK

--JYB



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]