If a #define
is used with no value, like
#define COMMAND_SPI()
does it take value 0 by default?
No, it evaluates to nothing. Literally the symbol gets replaced with nothing.
However, once you have #define FOO
, the preprocessor conditional #ifdef FOO
will now be true.
Note also that in gcc
and possibly other compilers, if you define a macro with -DFOO
on the command line, that evaluates to 1
by default.
Since the OP updated his question to reference function-like macros, let's consider a small example.
#define FOO
#define BAR()
FOO
BAR
BAR()
This is not a valid C
program, but the preprocessor does not care.
If I compile this with gcc -E Input.c
, I get a blank, followed by BAR
followed by another blank. This is because the first and third expressions evaluate to nothingness, and the middle expression is not expanded because there are no ()
after it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With