cpp.info: Common Predefined Macros

Go forward to System-specific Predefined Macros
Go backward to Standard Predefined Macros
Go up to Predefined Macros
Go to the top op cpp

Common Predefined Macros

   The common predefined macros are GNU C extensions.  They are
available with the same meanings regardless of the machine or operating
system on which you are using GNU C.  Their names all start with double
     These macros are defined by all GNU compilers that use the C
     preprocessor: C, C++, and Objective-C.  Their values are the major
     version, minor version, and patch level of the compiler, as integer
     constants.  For example, GCC 3.2.1 will define `__GNUC__' to 3,
     `__GNUC_MINOR__' to 2, and `__GNUC_PATCHLEVEL__' to 1.  They are
     defined only when the entire compiler is in use; if you invoke the
     preprocessor directly, they are not defined.
     `__GNUC_PATCHLEVEL__' is new to GCC 3.0; it is also present in the
     widely-used development snapshots leading up to 3.0 (which identify
     themselves as GCC 2.96 or 2.97, depending on which snapshot you
     If all you need to know is whether or not your program is being
     compiled by GCC, you can simply test `__GNUC__'.  If you need to
     write code which depends on a specific version, you must be more
     careful.  Each time the minor version is increased, the patch
     level is reset to zero; each time the major version is increased
     (which happens rarely), the minor version and patch level are
     reset.  If you wish to use the predefined macros directly in the
     conditional, you will need to write it like this:

/* Test for GCC > 3.2.0 */
#if _GNUC_ > 3 || \
(__GNUC__ == 3 && (__GNUC_MINOR__ > 2 || \
(__GNUC_MINOR__ == 2 && \

     Another approach is to use the predefined macros to calculate a
     single number, then compare that against a threshold:

#define GCC_VERSION (__GNUC__ * 10000 \
+ _GNUC_MINOR_ * 100 \
/* Test for GCC > 3.2.0 */
#if GCC_VERSION > 30200

     Many people find this form easier to understand.
     This macro is defined, with value 1, when the Objective-C compiler
     is in use.  You can use `__OBJC__' to test whether a header is
     compiled by a C compiler or a Objective-C compiler.
     The GNU C++ compiler defines this.  Testing it is equivalent to
     testing `(__GNUC__ && __cplusplus)'.
     GCC defines this macro if and only if the `-ansi' switch, or a
     `-std' switch specifying strict conformance to some version of ISO
     C, was specified when GCC was invoked.  It is defined to `1'.
     This macro exists primarily to direct GNU libc's header files to
     restrict their definitions to the minimal set found in the 1989 C
     This macro expands to the name of the main input file, in the form
     of a C string constant.  This is the source file that was specified
     on the command line of the preprocessor or C compiler.
     This macro expands to a decimal integer constant that represents
     the depth of nesting in include files.  The value of this macro is
     incremented on every `#include' directive and decremented at the
     end of every included file.  It starts out at 0, it's value within
     the base file specified on the command line.
     This macro expands to a string constant which describes the
     version of the compiler in use.  You should not rely on its
     contents having any particular form, but it can be counted on to
     contain at least the release number.
     These macros describe the compilation mode.  `__OPTIMIZE__' is
     defined in all optimizing compilations.  `__OPTIMIZE_SIZE__' is
     defined if the compiler is optimizing for size, not speed.
     `__NO_INLINE__' is defined if no functions will be inlined into
     their callers (when not optimizing, or when inlining has been
     specifically disabled by `-fno-inline').
     These macros cause certain GNU header files to provide optimized
     definitions, using macros or inline functions, of system library
     functions.  You should not use these macros in any way unless you
     make sure that programs will execute with the same effect whether
     or not they are defined.  If they are defined, their value is 1.
     GCC defines this macro if and only if the data type `char' is
     unsigned on the target machine.  It exists to cause the standard
     header file `limits.h' to work correctly.  You should not use this
     macro yourself; instead, refer to the standard macros defined in
     This macro expands to a single token (not a string constant) which
     is the prefix applied to CPU register names in assembly language
     for this target.  You can use it to write assembly that is usable
     in multiple environments.  For example, in the `m68k-aout'
     environment it expands to nothing, but in the `m68k-coff'
     environment it expands to a single `%'.
     This macro expands to a single token which is the prefix applied to
     user labels (symbols visible to C code) in assembly.  For example,
     in the `m68k-aout' environment it expands to an `_', but in the
     `m68k-coff' environment it expands to nothing.
     This macro will have the correct definition even if
     `-f(no-)underscores' is in use, but it will not be correct if
     target-specific options that adjust this prefix are used (e.g. the
     OSF/rose `-mno-underscores' option).
     These macros are defined to the correct underlying types for the
     `size_t', `ptrdiff_t', `wchar_t', and `wint_t' typedefs,
     respectively.  They exist to make the standard header files
     `stddef.h' and `wchar.h' work correctly.  You should not use these
     macros directly; instead, include the appropriate headers and use
     the typedefs.
     This macro is defined, with value 1, if the compiler uses the old
     mechanism based on `setjmp' and `longjmp' for exception handling.