I'd like to see all macros that are defined by the invocation of the compiler I'm using. Is there any way to do this? I have seen in the manual it says you can use cpp -dM
but this doesn't work for me. Perhaps I'm doing something wrong?
When I run:
cpp -dM
I get no output at all from the preprocessor. If I try adding -dM
as an option on gcc, I don't notice any difference.
The C preprocessor is a macro processor that is used automatically by the C compiler to transform your program before actual compilation. It is called a macro processor because it allows you to define macros, which are brief abbreviations for longer constructs.
To check – A Macro is defined or not, we use #ifdef preprocessor directive. To check whether a Macro is defined or not in C language – we use #ifdef preprocessor directive, it is used to check Macros only. If MACRO_NAME is defined, then the compiler will compile //body (a set of statements written within the #ifdef ...
Note that __SIZE_TYPE__ isn't a variable; it's a type. Compilers other than GCC probably do not provide it, unless they're trying to be compatible with GCC. If you want size_t , include <stddef. h> if you aren't including any of the other headers (such as <stdio. h> , <string.
You can use:
gcc -dM -E - < /dev/null
Note that you can also get the compiler macros in addition with this command:
touch bla.c && gcc -dM -E bla.c
For example on my computer:
$ touch bla.c && gcc -dM -E bla.c | wc -l
486
$ gcc -dM -E - < /dev/null | wc -l
124
$
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