Detect which target CPU a GCC configured for?

c-preprocessor, gcc

Solution

To detect the architecture at compile time in the source code use a predefined macro.

According to this article, it will always have a name in a form `_arch_` or `__arch__` where the arch is the name of the target architecture. To see what exactly defined, use the following command:

touch foo.h; cpp -dM foo.h; rm foo.h

It will print out all predefined macros.

To print out on the command line, try:

gcc -dumpmachine

It will show the target the GCC is is built for.

Problem

Possible Duplicate: Detecting CPU architecture compile-time Is there a define that GCC sets which tells which CPU (x86/amd64/ppc/etc) GCC is configured for? So I can use it like: ``` #ifdef PPCARCH dosomething(); #endif ```

Original source

Related problems