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 C, since the defined(MACRO) preprocessor operator works only inside #if's. Is there a way to do this?
What I really like to do is to write:
ASSERT(UART, var >= 0);
where
#define ASSERT(NAME, TEST) \ do { \ if (defined(NAME) && !(TEST)) \ printf("Assert failed"); \ } while(0)
thus I could turn on ASSERT checks when a macro is defined and if it is not defined, then the asserts should not be checked. If you try to do this, then you get:
implicit declaration of function `defined'
which is quite understandable since the GCC compiler does not find the defined()
preprocessor operator.