Techie

Dump gcc built-in #defs

This is very useful if you have say two different compilers compiling the same piece of code and you want to execute some special code only for one of the compilers. Do this:

#> gcc -E -dD -
ctrl-D


This will dump all the inbuilt #defs. For example, if gcc was cross compiled for mips target, you’d have something like this somewhere in that dump:

...
# 1 "<built-in>"
#define __mips__ 1
# 1 "<built-in>"
#define _mips 1
# 1 "<built-in>"
#define mips 1
# 1 "<built-in>"
#define __mips64 1
# 1 "<built-in>"
...


and if your compiler was compiled with target intel, you’d see this:

...
# 1 "<built-in>"
#define __i386 1
# 1 "<built-in>"
#define __i386__ 1
# 1 "<built-in>"
#define i386 1
# 1 "<built-in>"
...


So in your code, you can do this:

# ifdef __mips__
/* mips specific code */
#endif

etc.
Cool eh?

Leave a Reply

Your email address will not be published. Required fields are marked *