• Advertisement

Archived

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

macros, with variable amounts of arguments

This topic is 5672 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

OK, I have a problem I''m trying to solve via macros. If there''s a better way let me know (after you''ve heard the problem). I''m trying to write some debugging routines that I only want to be compiled during debugging (suprisingly enough). I also wanted them to be flexible enough to provide whatever information I needed to output for a particular error (hence variable number of arguments). Further to this, I wanted them to automatically embed the line and file the error occured at. So I have my function, something like: int Error(int line, char *file, char *msg, ...); My ideal macro would be: #define ERROR(__LINE__, __FILE__, message, ...) But the compiler doesn''t like the ellipses. I''ve tried a bunch of ways to get this to work but nothing has been successful. I found some GCC documentation about variadic macros (just a search on Google found this) which appears to do what I want. However, VC++ 6 doesn''t seem to support it. Any ideas (short of switching to GCC) or alternative solutions would be welcome. Thanks, -Mezz

Share this post


Link to post
Share on other sites
Advertisement
Yup, variable number of arguments macros aren''t allowed in pre C99.

Look at the MFC TRACE macro implementation to see how it is done though, you don''t use brackets in the macro.

Share this post


Link to post
Share on other sites

  • Advertisement