# 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.

## 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 on other sites
Try:
 #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.

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
16
5. 5

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632593
• Total Posts
3007277

×