5

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
Community
  • 1
  • 1
Prof. Falken
  • 23,276
  • 18
  • 98
  • 168

1 Answers1

5

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.

Prof. Falken
  • 23,276
  • 18
  • 98
  • 168
Serge
  • 6,040
  • 15
  • 27