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.

Aiee :)


> Alexandre Oliva wrote:
> > On May 29, 2000, Gigi Sullivan <> wrote:
> >
> > Nope.  If you pass a list of pointers, the last of which is NULL, then
> > you can certainly expect va_arg to work correctly on all platforms, as
> > long as you tell it each argument is the appropriate pointer type.
> >
> > >       Not all pass parameters on the stack (that could grows towards
> > >       lower/upper address).
> >
> > va_arg will take care of this for you.

	Yep, this is true, but I'd like to avoid explicity NULL in parameter
	list. There's no true reason to avoid NULL, only it's more pretty.

> >
> > > Could be this an addendum to the current gcc?
> >
> > What kind of extension are you thinking of?
> >

	I was thinking about some pretty __builtin* feature that could
	returns the number of argument passed to a function ...
	(like __builtin_next_arg(last) is used in some va_arg implementation
	I guess).

> This was initially stated to be for a C program, or .c anyway, and I'm
> wondering what stage of development this program is at.  If early and there
> wouldn't be much to convert, then couldn't this be done in C++, using
> inherent language support?

	Yep, I know... but I cannot (don't want to) write it in C++.

> Isn't there a getopt or getopts C function?  There is for shell script and
> it (I believe) requires -{option}'s, i.e., option switches, to be used (not
> sure if the switches are necessary), but seem to remember reading
> somewhere, maybe in Perl, that the script getopt function was associated
> with the C function, and this would be GNU C.  Perl has been ported to
> other OSs and I believe it's getopt function is supported on all;
> therefore, GNU C getopt or what ever the correct name is would probably
> also be equally supported or portable.
> Check for the getopt function (name may be a little different) to see if
> this is portable and exists.

	Well, I really never looked at getopt sources, but I guess that
	getopt typically use the well-known `char *fmt' stuff then
	with while/switch/va_arg we can get all (ok, man va_arg for example
	and see the EXAMPLE section).

	Uhm ... related question (well it's the same question applied to other
	stuff ;)):

	consider this macro

	#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?


	#define EXPAND_ARGS(some, args...) \
	do { \
		int argc = $$args /* I'm mad! :) something that can get the #args */ \
		ex_args(some, argc, ##args); \
	} while(0)

	so in ex_args, I can know the parameter number, by getting argc value
	(and can use va_arg (through a for cycle, for example).

bye bye (and thx :))

			-- gg sullivan

Lorenzo Cavallaro	`Gigi Sullivan' <>

Until I loved, life had no beauty;
I did not know I lived until I had loved. (Theodor Korner)

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