Jump to content
  • Advertisement
Sign in to follow this  

Minor Define Problem

This topic is 2218 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 allow my error reports to automatically include the file and line number using defines.

Like so:

#define NPERROR( x ) EngineAPI()->Error( __FILE__, __LINE__, x );

Which calls this method:

void Error( const char* file, uintn line, const char* format, ... );

I'm trying to use the define macro like so:

NPERROR( "Chicken named '%s' ate the game code!", chickenName )

However this causes issues because it expects only one parameter in the define and it interprets the commas as new parameters!
How do you think I can fix this while hopefully still including the file and line number automatically?

Thanks as usual!

Share this post

Link to post
Share on other sites

#define NPERROR(...) EngineAPI()->Error( __FILE__, __LINE__, __VA_ARGS__ );

Note variadic macros are a relatively recent C++ language feature, only being standardized in C++11. They've been part of C since C99, and have been widely implemented in C++ as an extension for a while now (ex: MSVC since 2005), but if you're trying to write portable code that targets older compilers, you may want to take a different approach.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!