This is the mail archive of the 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]

Re: Knowing the number of variable arguments.

On May 30, 2000, Gigi Sullivan <> wrote:

> 	I was thinking about some pretty __builtin* feature that could
> 	returns the number of argument passed to a function ...

This just can't be computed in general.  There's no such thing as a
magic terminator that GCC could use for that.  And using the FP is not
always possible.

> 	#define EXPAND_ARGS(some, args...)  ex_args(some, ##args)

> 	Is there a way to get the number of parameters EXPAND_ARGS will expand to?
> 	I means is there some pretty gcc-related-feature to get this?

If all args are of the same type, and you know that type, you could
declare an auto array, initialize it with ##args, then divide the size
of the array by the size of a single element.  But this would evaluate
the arguments twice.

But then, why don't you use

#define EXPAND_ARGS(some, args...) ex_args(some, ##args, NULL)


Alexandre Oliva    Enjoy Guaranį, see
Cygnus Solutions, a Red Hat company        aoliva@{redhat, cygnus}.com
Free Software Developer and Evangelist    CS PhD student at IC-Unicamp
oliva@{,}   Write to mailing lists, not to me

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