I would like to write code in C something like this:
if(defined(MACRO)) ... else ...
but I could not find any way to do this in
Ok, based on the previous post I got this idea, which seems to work:
#define DEFINEDX(NAME) ((#NAME)[0] == 0) #define DEFINED(NAME) DEFINEDX(NAME)
This will check if NAME is defined and therefore it expands to the empty string with 0 at its first character, or it is undefined in which case it is not the empty string. This works with GCC, so one can write
if( DEFINED(MACRO) ) ...