Archived

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

MACRO(...)

This topic is 5142 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
Some preprocessors let you do it.
It''s not a standard feature.
Check your documentation.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
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