Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anyway to see list of preprocessor defined macros?

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.

like image 973
Brandon Yates Avatar asked Jun 05 '12 20:06

Brandon Yates


People also ask

Which preprocessor is used define macros?

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.

How do I know if a macro is defined?

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 ...

What is __ Size_type __?

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.


1 Answers

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
$
like image 80
ouah Avatar answered Oct 02 '22 23:10

ouah