Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Macro question

Reply
Thread Tools

Macro question

 
 
John Blevin
Guest
Posts: n/a
 
      10-16-2003
I can play games with macro names, to do something like:

#define MACRO_TYPE_FOO(arg) { some_function(arg); }
#define MACRO_TYPE(arg1, arg2) MACRO_TYPE_##arg1(arg2)

MACRO_TYPE(FOO, 5);

But if I try to define a macro to represent the arguments, it doesn't
work:

#define my_args FOO, 5

MACRO_TYPE(my_args);

In this case it first evaluates the MACRO_TYPE and forms
a MACRO_TYPEmy_args (which of course is not defined), it does this
before expanding the my_args. Do you know if there is a way
to get it to expand the my_args before the MACRO_TYPE?

Thanks!

- John

 
Reply With Quote
 
 
 
 
Dave Thompson
Guest
Posts: n/a
 
      10-20-2003
On Thu, 16 Oct 2003 11:23:21 -0400, John Blevin <(E-Mail Removed)>
wrote:

> I can play games with macro names, to do something like:
>
> #define MACRO_TYPE_FOO(arg) { some_function(arg); }
> #define MACRO_TYPE(arg1, arg2) MACRO_TYPE_##arg1(arg2)
>
> MACRO_TYPE(FOO, 5);
>
> But if I try to define a macro to represent the arguments, it doesn't
> work:
>
> #define my_args FOO, 5
>
> MACRO_TYPE(my_args);
>
> In this case it first evaluates the MACRO_TYPE and forms
> a MACRO_TYPEmy_args (which of course is not defined), it does this
> before expanding the my_args. Do you know if there is a way
> to get it to expand the my_args before the MACRO_TYPE?
>

#define INVOKE_MACRO_TYPE(args) MACRO_TYPE(args)
INVOKE_MACRO_TYPE(my_args);

at least in gcc-2.95; I'm *pretty* sure it's standard, but this is one
of the more arcane areas of the standard and ICBW.

- David.Thompson1 at worldnet.att.net
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dedicated Macro or Normal Macro? John Ortt Digital Photography 5 11-22-2005 12:43 PM
Macro lens on a camera with a macro setting??? mitchell.chris@gmail.com Digital Photography 2 09-28-2005 07:55 AM
in S.E. Asia : Canon EOS 300d with 100 macro ED vs. Nikon D70 with Nikon 105 macro ? J. Cod Digital Photography 0 09-29-2004 05:46 AM
#define macro to enclose an older macro with strings Dead RAM C++ 20 07-14-2004 10:58 AM
macro name from macro? D Senthil Kumar C Programming 1 09-21-2003 07:02 PM



Advertisments