Wednesday, January 9, 2013

How to inspect expanded C macros with gcc/gcc+

Sometimes you get compilation errors in gcc/g++ and you'd like to inspect the output from the C compiler pre-processor to figure out why certain macros were expanded in such as way to cause an error.
The solution is simply to remove the -o and -c options from your gcc/g++ command line and replace it with

gcc/g++ -E -dD

this will generate on your terminal only the C pre-processor output that is eventually fed to the C/C++ compiler.

For example you are trying to compile Mozilla SpiderMonkey 1.7 and one of  the compiler lines is the following:


To see the expanded C macros run the following command:



Note: Only a member of this blog may post a comment.