Disabling the expansion of certain macros in error/warning outputs

Viewed 420

I have a very frequently used, somewhat complex macro (let's call it MAC(...) for the sake of this question), which must be a macro (as it's very type-generic). The macro behaves syntactically, like a function call but internally calls over 10 other macros.

Consequently if I make an error while calling MAC() e.g., if I do: MAC(1-) gcc/clang will dump at me the quite long preprocessor stack trace of MAC() which I'm not at all intersted in.

If I define MAC() like so:

#if DEBUG_MAC
    int MAC(); //so I get a nice preprocessor stack trace
#else
    #define MAC(...) //here would come the actual definition
#endif

and then, upon encountering an error I recompile with -DDEBUG_MAC, I get a nice (=nonexistent) preprocessor stack trace but this approach feels clumsy and only works for diagnosing hard errors, not warnings.

Is there a way to get gcc or clang to behave like this, i.e., treat a macro like an opaque function call for the purposes of error reporting, without doing this kind of declaration/macro shuffling?

0 Answers
Related