How can we check wheather a Macro is defined or not, and if defined then with what value? I tried doing gdb, but we can not see the Macros in GDB, as MACROs are replaced at the time of Precompilation only.
Is there any way in GCC compiler that we can see the precompiled file, which is created by the compiler before creating the object file (*.o) ?
You can use -E
flag of gcc to get the pre-processed output. This output will contain macros expanded instead of their names. You can find more information here.
Inside of a C source file, you can use the #ifdef
macro to check if a 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;
}
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