Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect which target CPU a GCC configured for? [duplicate]

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
like image 370
Prof. Falken Avatar asked Sep 26 '12 20:09

Prof. Falken


1 Answers

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.

like image 157
Serge Avatar answered Sep 30 '22 15:09

Serge