Detecting CPU architecture compile-time

Alex B picture Alex B · Sep 30, 2008 · Viewed 68.3k times · Source

What is the most reliable way to find out CPU architecture when compiling C or C++ code? As far as I can tell, different compilers have their own set of non-standard preprocessor definitions (_M_X86 in MSVS, __i386__, __arm__ in GCC, etc).

Is there a standard way to detect the architecture I'm building for? If not, is there a source for a comprehensive list of such definitions for various compilers, such as a header with all the boilerplate #ifdefs?

Answer

Serge picture Serge · Sep 30, 2008

Here is some information about Pre-defined Architecture Macros and other types of pre-defined macros.

This question asks where they are defined in the GCC source code.