Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22042

Using defined(MACRO) inside the C if statement

$
0
0

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.


Viewing all articles
Browse latest Browse all 22042

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>