Search code examples
iosobjective-cxcodemacrosvariadic

Xcode compiler errors when using ##__VA_ARGS__


Here is my customized NSLog.

#define NSLog(fmt, ...) printf("🌳🌳🌳%s,%d\n %s\n\n", __PRETTY_FUNCTION__, __LINE__, [NSString stringWithFormat:fmt, ##__VA_ARGS__].UTF8String)

This log is work good on another project, but it occurred 4 error when compiler time in current project. If using __VA_ARGS__, like #define NSLog(...) NSLog(__VA_ARGS__), it's going to compile successful. I think that maybe caused in Building Setting.

error 1

error 2

error 3

error 4

It's anyone has any idea to help me to solve this.


Solution

  • Check that the header file declaring this imports Foundation. Check that you don't have NSLog defined somewhere else as well and finally, really not a good idea to redefine NSLog. You're probably better off adopting a logging framework or defining your own like this:

    #define MELog(fmt, ...) NSLog("🌳🌳🌳%s,%d\n %s\ ....