Home > Miscellaneous > Dump gcc built-in #defs

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?

Advertisements
Categories: Miscellaneous
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: