variadic macros

C

Christof Warlich

Hi,

is there any way to access individual elements in the body
of a variadic macro? I only found __VA_ARGS__, which always
expands to the complete list.

Thanks for any help,

Christof
 
C

Christof Warlich

It would already help if there would be a way to have something
that expands to the number of arguments being passed to the variadic macro.
 
A

Antoninus Twink

is there any way to access individual elements in the body
of a variadic macro? I only found __VA_ARGS__, which always
expands to the complete list.

Twelve hours, and not a single language lawyer has come along to explain
that you can't. That's because your question is about C99, and the
luddite regulars in this group won't tolerate any discussion of C
standards more recent than the fall of the Berlin Wall.

Anyway, to answer your question, no there's no way in standard C...
there's not even any way using gcc extensions. I don't know about MS or
lcc extensions - maybe you can with them.

To understand why the answer is no, think about how you'd go about
finding out how many arguments were passed to your variadic function...
now ponder doing that in a macro.

The only purpose of variadic macros is to facilitate providing default
arguments for calls to variadic functions, like the usual
fprintf(stderr, __VA_ARGS__) example.
 
P

Peter Nilsson

Not in standard C99.
It would already help if there would be a way to
have something that expands to the number of
arguments being passed to the variadic macro.

There's no shortage on the wish list for standard C.
However that doesn't mean that your actual problem
doesn't have a simple solution.

Perhaps you might like to mention the real problem.
It may be solvable quite easily in standard C.
 
V

vippstar

Not in standard C99. 6.10.3 p 5
The identiï¬er _ _VA_ARGS_ _ shall occur only in the replacement-list
of a function-like macro that uses the ellipsis notation in the parameters..
 
V

vippstar

Whoops; I just realized you meant that accessing individual elements
in the body of a variadic macro is not possible in C99, which is true.
My apologies.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

recursive variadic macros 9
C99's variadic macros. 7
Variadic debug macros 5
macro trick 5
variadic macro 2
I know VBA (macros) - nothing else! 0
Endianness macros 48
Variadic macros 3

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top