Determine for which target CPU GCC is configured?

Possible duplicate:
CPU architecture compile time detection

Is there a definition that GCC installs, which indicates which CPU (x86 / amd64 / ppc / etc) GCC is configured for?

Therefore, I can use it like:

#ifdef PPCARCH
  dosomething();
#endif
+5
source share
1 answer

To discover architecture at compile time in source code, use a predefined macro.

In accordance with this article, it will always have a name in the form _arch_or __arch__, where arch is the name of the target architecture. To find out what exactly is defined, use the following command:

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

It prints all predefined macros.

To print on the command line, try:

gcc -dumpmachine

, GCC.

+5

All Articles