Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

aboeing

MACRO(...)

This topic is 5336 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there some way to write a macro which will handle the ellipsis case? Or do you just have to type out hundreds of macros to take into consideration all the different possible cases? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Leave the brackets out of the macro and map it to a function taking variable numbers of arguments.

Check out the TRACE macro from MFC if you are using MSVC.

It''s a bit like
#define TRACE printf

so TRACE(stuff, nonsense); maps to printf(stuff, nonsense);

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Share this post


Link to post
Share on other sites
Variable argument macros were standardized in the 1999 revision of the C language, so most recent C compilers will suppor macros with variable arguments. You use the ellipses in a trailing context in the macro definition and apply __VA_ARGS__ to access the parameters.

Example:

#define DEBUGF(f,...) \
(fprintf(dbgf, "%s(): ", f), fprintf(dbgf, __VA_ARGS__))

If you''re using C++, most C++ compilers that support modern C will will have variable argument macros as well. For example: gcc

Share this post


Link to post
Share on other sites
Thanks heaps for the help!

Paradigm Shifter: Yeah, I was taking this approach before, but now Ive got a situation where I cant do that

SiCrane: Awesome! Thanks thats just what I was looking for.

Unfortunately it appears VC6 doesnt support that macro, but I think this is the last straw, Im dropping VC6 support. Just too many features its missing. (Frunny: you wouldnt happen to know if VC6 has a MS specific version of this?)

Thanks guys.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!