To check if a macro is defined or not

How can we verify that a macro is defined or not, and if defined, with what value? I tried to do gdb, but we don’t see macros in GDB, because MACROs are replaced only during Precompilation.

Is there any way in the GCC compiler so that we can see the precompiled file that the compiler creates before creating the object file (* .o)?

+4
source share
2 answers

You can use the -E gcc flag to get pre-processed output. This output will contain macros extended instead of their names. You can find more information here .

+7
source

Inside the C source file, you can use the #ifdef macro to check if the macro is defined.

 #include <stdio.h> #ifdef MY_MACRO char msg[] = "My macro is defined"; #else char msg[] = "My macro is NOT defined"; #endif int main(int argc, char **argv) { printf("%s\n", msg); return 0; } 
+4
source

All Articles