This question regards the legality of using a preprocessor directive within a function-like macro's argument.
Consider the following code. #ifdef
is used inside MY_MACRO
's argument :
#include <iostream>
// Macro to print a message along with the line number the macro appears at
#define MY_MACRO( msg ) { std::cerr << "Line " << __LINE__ << "\t- "<< msg << '\n'; }
int main()
{
// Print the current build configuration
MY_MACRO(
#ifdef NDEBUG // <-- preprocessor directive in macro argument
"Release"
#else
"Debug"
#endif
)
}
gcc 12 is fine with it, msvc 19 does not allow it : https://godbolt.org/z/G8j4aTG6j
What does the standard have to say about it?