• Advertisement

Archived

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

C++ ellipsis in a macro for debugging?

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

I'm trying to set up my debugging scheme for my engine. Here's what Write() looks like: bool Write (char*, ...); I want to debug like this: WRITE_ERROR("Bad filename - %s", Filename); with WRITE_ERROR being some kind of macro or something that prints out __FILE__ and __LINE__ as well without having me write out that extra line of code for each WRITE_ERROR statement. I would like something like this, although I don't think it's possible: #define WRITE_ERROR(STR, ...) { Write(STR, __FILE__, __LINE__); } Any ideas how to do this? Thanks
[JESUS SAVES] [edited by - gilligancoder on August 8, 2003 9:33:14 PM] [edited by - gilligancoder on August 8, 2003 9:34:13 PM]

Share this post


Link to post
Share on other sites
Advertisement
One possibility:

#define WRITE_ERROR Write("%s:%i: ", __FILE__, __LINE__), Write

This requires care, due to operator precedence.

Share this post


Link to post
Share on other sites
Hey, that macro works great. I didn''t realize you could just put a comma into a macro like that. Learned something new though, and now I can send my error message with a one-liner with 4 lines of output. Thanks


[JESUS SAVES]

Share this post


Link to post
Share on other sites

  • Advertisement