C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Variadic Macros

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Michael D. Borghardt
Guest





PostPosted: Sat Mar 06, 2004 12:08 am    Post subject: Variadic Macros Reply with quote



Trying to find information on variadic macros.

Can you get specific parameters?

#define Test(...) printf("%s", ##__VAR_ARGS__)

I can't do this to get the first parameter

#define Test(...) printf("%s", var_arg(__VAR_ARGS__, char*))

or

#define Test(...) printf("%s", var_arg(*__VAR_ARGS__, char*))

or

#define Test(...) printf("%s", var_arg(*##__VAR_ARGS__, char*))




[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Paul Mensonides
Guest





PostPosted: Sat Mar 06, 2004 9:59 am    Post subject: Re: Variadic Macros Reply with quote



Michael D. Borghardt wrote:
Quote:
Trying to find information on variadic macros.

Variadic macros are not currently part of C++, so you should probably ask in a C
newsgroup.

Quote:
Can you get specific parameters?

Yes, however sometimes a little preprocessor metaprogramming is required to
extract them. Here's an example:

#define CAT(a, ...) PRIMITIVE_CAT(a, __VA_ARGS__)
#define PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__

#define EXPAND(...) __VA_ARGS__

#define VARIADIC_ELEM(n, ...)
EXPAND(
PRIMITIVE_CAT(VARIADIC_ELEM_, n)
VARIADIC_ELEM_I(__VA_ARGS__,,,,,,,,,,)
)
/**/
#define VARIADIC_ELEM_I(a, b, c, d, e, f, g, h, i, j, ...)
(a, b, c, d, e, f, g, h, i, j)
/**/
#define VARIADIC_ELEM_0(a, b, c, d, e, f, g, h, i, j) a
#define VARIADIC_ELEM_1(a, b, c, d, e, f, g, h, i, j)
#define VARIADIC_ELEM_1(a, b, c, d, e, f, g, h, i, j)
#define VARIADIC_ELEM_1(a, b, c, d, e, f, g, h, i, j)
#define VARIADIC_ELEM_1(a, b, c, d, e, f, g, h, i, j)
#define VARIADIC_ELEM_1(a, b, c, d, e, f, g, h, i, j)
#define VARIADIC_ELEM_1(a, b, c, d, e, f, g, h, i, j)
#define VARIADIC_ELEM_1(a, b, c, d, e, f, g, h, i, j)
#define VARIADIC_ELEM_1(a, b, c, d, e, f, g, h, i, j)



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Paul Mensonides
Guest





PostPosted: Sat Mar 06, 2004 10:04 am    Post subject: Re: Variadic Macros Reply with quote



[Sorry to all for the double post; the other post was sent a bit early.]

{When this happens please send a message to the moderators, preferably
with the sequence number you get when a post is acknowledged. I think
that we moderators all read such mail before we start moderating posts.
Posts often go the different moderators, and even when they go to the
same one, the earlier post is likely to have been accepted unless warned
in advance. -mod}

Michael D. Borghardt wrote:
Quote:
Trying to find information on variadic macros.

Variadic macros are not currently part of C++, so you should probably ask in a C
newsgroup.

Quote:
Can you get specific parameters?

Yes, however sometimes a little preprocessor metaprogramming is required to
extract them. Here's an example:

#define CAT(a, ...) PRIMITIVE_CAT(a, __VA_ARGS__)
#define PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__

#define EXPAND(...) __VA_ARGS__

#define VARIADIC_ELEM(n, ...)
EXPAND(
PRIMITIVE_CAT(VARIADIC_ELEM_, n)
VARIADIC_ELEM_I(__VA_ARGS__,,,,,,,,,,)
)
/**/
#define VARIADIC_ELEM_I(a, b, c, d, e, f, g, h, i, j, ...)
(a, b, c, d, e, f, g, h, i, j)
/**/
#define VARIADIC_ELEM_0(a, b, c, d, e, f, g, h, i, j) a
#define VARIADIC_ELEM_1(a, b, c, d, e, f, g, h, i, j) b
#define VARIADIC_ELEM_2(a, b, c, d, e, f, g, h, i, j) c
#define VARIADIC_ELEM_3(a, b, c, d, e, f, g, h, i, j) d
#define VARIADIC_ELEM_4(a, b, c, d, e, f, g, h, i, j) e
#define VARIADIC_ELEM_5(a, b, c, d, e, f, g, h, i, j) f
#define VARIADIC_ELEM_6(a, b, c, d, e, f, g, h, i, j) g
#define VARIADIC_ELEM_7(a, b, c, d, e, f, g, h, i, j) h
#define VARIADIC_ELEM_8(a, b, c, d, e, f, g, h, i, j) i
#define VARIADIC_ELEM_9(a, b, c, d, e, f, g, h, i, j) j

VARIADIC_ELEM(0, +, -, *, /, %) // +
VARIADIC_ELEM(1, +, -, *, /, %) // -
VARIADIC_ELEM(2, +, -, *, /, %) // *
VARIADIC_ELEM(3, +, -, *, /, %) // /
VARIADIC_ELEM(4, +, -, *, /, %) // %

Regards,
Paul Mensonides



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.