1

this is the actual macro:

#ifdef DEBUG                                                                   
#define debug(funcname, format, ...) \                                         
        printf(BOLD UNDERLINED REVERSE \                                    
        "DEBUG IN " __FILE__ \                                             
        " LINE " __LINE__ ":" \                                            
        RESET UNDERLINED REVERSE \                                         
        "In " funcname \                                                   
        RESET REVERSE format RESET, ##__VA_ARGS__)                         
#else                                                                          
#define debug(funcname, format, ...)                                           
#endif                                                                        

Where all the constant used are well defined string constants. I call it with something like:

char message[] = "Hello StackOverflow !\n";
debug("main()", "Message: %s\n", message);

But I get the message

error: expected ‘)’ before numeric constant debug("main()", "Message: ", message); poiting at the closing parenthese.

It is weird because I first tested the macro, and now that the project has advanced with the team it doesn't work...

  • just to help you out, the predefined name: `__func__` (note lower case) will return the function name, so you do not need to hardcode the function names into the macro calls – user3629249 Mar 29 '16 at 01:16

1 Answers1

5

That's because

 " LINE " __LINE__ ":"

expands to the syntactically invalid

 " LINE " 42 ":"

since __LINE__ is an integer, not a string literal that can be concatenated.

Jens
  • 69,818
  • 15
  • 125
  • 179
  • Thanks man ! I should have thought about that, but preprocessor error messages can really be uncomprehensible sometimes. – Nicolas Scotto Di Perto Mar 29 '16 at 18:55
  • @NicolasScottoDiPerto You can fix this either by using `"%d"` in the format and moving `__LINE__` just before the `##__VA_ARGS__`; or by stringyfing the `__LINE__` expansion. – Jens Mar 29 '16 at 19:28