cpp: Common Predefined Macros
1
1 3.7.2 Common Predefined Macros
1 ------------------------------
1
1 The common predefined macros are GNU C extensions. They are available
1 with the same meanings regardless of the machine or operating system on
1 which you are using GNU C or GNU Fortran. Their names all start with
1 double underscores.
1
1 '__COUNTER__'
1 This macro expands to sequential integral values starting from 0.
1 In conjunction with the '##' operator, this provides a convenient
1 means to generate unique identifiers. Care must be taken to ensure
1 that '__COUNTER__' is not expanded prior to inclusion of
1 precompiled headers which use it. Otherwise, the precompiled
1 headers will not be used.
1
1 '__GFORTRAN__'
1 The GNU Fortran compiler defines this.
1
1 '__GNUC__'
1 '__GNUC_MINOR__'
1 '__GNUC_PATCHLEVEL__'
1 These macros are defined by all GNU compilers that use the C
1 preprocessor: C, C++, Objective-C and Fortran. Their values are
1 the major version, minor version, and patch level of the compiler,
1 as integer constants. For example, GCC version X.Y.Z defines
1 '__GNUC__' to X, '__GNUC_MINOR__' to Y, and '__GNUC_PATCHLEVEL__'
1 to Z. These macros are also defined if you invoke the preprocessor
1 directly.
1
1 If all you need to know is whether or not your program is being
1 compiled by GCC, or a non-GCC compiler that claims to accept the
1 GNU C dialects, you can simply test '__GNUC__'. If you need to
1 write code which depends on a specific version, you must be more
1 careful. Each time the minor version is increased, the patch level
1 is reset to zero; each time the major version is increased, the
1 minor version and patch level are reset. If you wish to use the
1 predefined macros directly in the conditional, you will need to
1 write it like this:
1
1 /* Test for GCC > 3.2.0 */
1 #if __GNUC__ > 3 || \
1 (__GNUC__ == 3 && (__GNUC_MINOR__ > 2 || \
1 (__GNUC_MINOR__ == 2 && \
1 __GNUC_PATCHLEVEL__ > 0))
1
1 Another approach is to use the predefined macros to calculate a
1 single number, then compare that against a threshold:
1
1 #define GCC_VERSION (__GNUC__ * 10000 \
1 + __GNUC_MINOR__ * 100 \
1 + __GNUC_PATCHLEVEL__)
1 ...
1 /* Test for GCC > 3.2.0 */
1 #if GCC_VERSION > 30200
1
1 Many people find this form easier to understand.
1
1 '__GNUG__'
1 The GNU C++ compiler defines this. Testing it is equivalent to
1 testing '(__GNUC__ && __cplusplus)'.
1
1 '__STRICT_ANSI__'
1 GCC defines this macro if and only if the '-ansi' switch, or a
1 '-std' switch specifying strict conformance to some version of ISO
1 C or ISO C++, was specified when GCC was invoked. It is defined to
1 '1'. This macro exists primarily to direct GNU libc's header files
1 to use only definitions found in standard C.
1
1 '__BASE_FILE__'
1 This macro expands to the name of the main input file, in the form
1 of a C string constant. This is the source file that was specified
1 on the command line of the preprocessor or C compiler.
1
1 '__INCLUDE_LEVEL__'
1 This macro expands to a decimal integer constant that represents
1 the depth of nesting in include files. The value of this macro is
1 incremented on every '#include' directive and decremented at the
1 end of every included file. It starts out at 0, its value within
1 the base file specified on the command line.
1
1 '__ELF__'
1 This macro is defined if the target uses the ELF object format.
1
1 '__VERSION__'
1 This macro expands to a string constant which describes the version
1 of the compiler in use. You should not rely on its contents having
1 any particular form, but it can be counted on to contain at least
1 the release number.
1
1 '__OPTIMIZE__'
1 '__OPTIMIZE_SIZE__'
1 '__NO_INLINE__'
1 These macros describe the compilation mode. '__OPTIMIZE__' is
1 defined in all optimizing compilations. '__OPTIMIZE_SIZE__' is
1 defined if the compiler is optimizing for size, not speed.
1 '__NO_INLINE__' is defined if no functions will be inlined into
1 their callers (when not optimizing, or when inlining has been
1 specifically disabled by '-fno-inline').
1
1 These macros cause certain GNU header files to provide optimized
1 definitions, using macros or inline functions, of system library
1 functions. You should not use these macros in any way unless you
1 make sure that programs will execute with the same effect whether
1 or not they are defined. If they are defined, their value is 1.
1
1 '__GNUC_GNU_INLINE__'
1 GCC defines this macro if functions declared 'inline' will be
1 handled in GCC's traditional gnu90 mode. Object files will contain
1 externally visible definitions of all functions declared 'inline'
1 without 'extern' or 'static'. They will not contain any
1 definitions of any functions declared 'extern inline'.
1
1 '__GNUC_STDC_INLINE__'
1 GCC defines this macro if functions declared 'inline' will be
1 handled according to the ISO C99 or later standards. Object files
1 will contain externally visible definitions of all functions
1 declared 'extern inline'. They will not contain definitions of any
1 functions declared 'inline' without 'extern'.
1
1 If this macro is defined, GCC supports the 'gnu_inline' function
1 attribute as a way to always get the gnu90 behavior.
1
1 '__CHAR_UNSIGNED__'
1 GCC defines this macro if and only if the data type 'char' is
1 unsigned on the target machine. It exists to cause the standard
1 header file 'limits.h' to work correctly. You should not use this
1 macro yourself; instead, refer to the standard macros defined in
1 'limits.h'.
1
1 '__WCHAR_UNSIGNED__'
1 Like '__CHAR_UNSIGNED__', this macro is defined if and only if the
1 data type 'wchar_t' is unsigned and the front-end is in C++ mode.
1
1 '__REGISTER_PREFIX__'
1 This macro expands to a single token (not a string constant) which
1 is the prefix applied to CPU register names in assembly language
1 for this target. You can use it to write assembly that is usable
1 in multiple environments. For example, in the 'm68k-aout'
1 environment it expands to nothing, but in the 'm68k-coff'
1 environment it expands to a single '%'.
1
1 '__USER_LABEL_PREFIX__'
1 This macro expands to a single token which is the prefix applied to
1 user labels (symbols visible to C code) in assembly. For example,
1 in the 'm68k-aout' environment it expands to an '_', but in the
1 'm68k-coff' environment it expands to nothing.
1
1 This macro will have the correct definition even if
1 '-f(no-)underscores' is in use, but it will not be correct if
1 target-specific options that adjust this prefix are used (e.g. the
1 OSF/rose '-mno-underscores' option).
1
1 '__SIZE_TYPE__'
1 '__PTRDIFF_TYPE__'
1 '__WCHAR_TYPE__'
1 '__WINT_TYPE__'
1 '__INTMAX_TYPE__'
1 '__UINTMAX_TYPE__'
1 '__SIG_ATOMIC_TYPE__'
1 '__INT8_TYPE__'
1 '__INT16_TYPE__'
1 '__INT32_TYPE__'
1 '__INT64_TYPE__'
1 '__UINT8_TYPE__'
1 '__UINT16_TYPE__'
1 '__UINT32_TYPE__'
1 '__UINT64_TYPE__'
1 '__INT_LEAST8_TYPE__'
1 '__INT_LEAST16_TYPE__'
1 '__INT_LEAST32_TYPE__'
1 '__INT_LEAST64_TYPE__'
1 '__UINT_LEAST8_TYPE__'
1 '__UINT_LEAST16_TYPE__'
1 '__UINT_LEAST32_TYPE__'
1 '__UINT_LEAST64_TYPE__'
1 '__INT_FAST8_TYPE__'
1 '__INT_FAST16_TYPE__'
1 '__INT_FAST32_TYPE__'
1 '__INT_FAST64_TYPE__'
1 '__UINT_FAST8_TYPE__'
1 '__UINT_FAST16_TYPE__'
1 '__UINT_FAST32_TYPE__'
1 '__UINT_FAST64_TYPE__'
1 '__INTPTR_TYPE__'
1 '__UINTPTR_TYPE__'
1 These macros are defined to the correct underlying types for the
1 'size_t', 'ptrdiff_t', 'wchar_t', 'wint_t', 'intmax_t',
1 'uintmax_t', 'sig_atomic_t', 'int8_t', 'int16_t', 'int32_t',
1 'int64_t', 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t',
1 'int_least8_t', 'int_least16_t', 'int_least32_t', 'int_least64_t',
1 'uint_least8_t', 'uint_least16_t', 'uint_least32_t',
1 'uint_least64_t', 'int_fast8_t', 'int_fast16_t', 'int_fast32_t',
1 'int_fast64_t', 'uint_fast8_t', 'uint_fast16_t', 'uint_fast32_t',
1 'uint_fast64_t', 'intptr_t', and 'uintptr_t' typedefs,
1 respectively. They exist to make the standard header files
1 'stddef.h', 'stdint.h', and 'wchar.h' work correctly. You should
1 not use these macros directly; instead, include the appropriate
1 headers and use the typedefs. Some of these macros may not be
1 defined on particular systems if GCC does not provide a 'stdint.h'
1 header on those systems.
1
1 '__CHAR_BIT__'
1 Defined to the number of bits used in the representation of the
1 'char' data type. It exists to make the standard header given
1 numerical limits work correctly. You should not use this macro
1 directly; instead, include the appropriate headers.
1
1 '__SCHAR_MAX__'
1 '__WCHAR_MAX__'
1 '__SHRT_MAX__'
1 '__INT_MAX__'
1 '__LONG_MAX__'
1 '__LONG_LONG_MAX__'
1 '__WINT_MAX__'
1 '__SIZE_MAX__'
1 '__PTRDIFF_MAX__'
1 '__INTMAX_MAX__'
1 '__UINTMAX_MAX__'
1 '__SIG_ATOMIC_MAX__'
1 '__INT8_MAX__'
1 '__INT16_MAX__'
1 '__INT32_MAX__'
1 '__INT64_MAX__'
1 '__UINT8_MAX__'
1 '__UINT16_MAX__'
1 '__UINT32_MAX__'
1 '__UINT64_MAX__'
1 '__INT_LEAST8_MAX__'
1 '__INT_LEAST16_MAX__'
1 '__INT_LEAST32_MAX__'
1 '__INT_LEAST64_MAX__'
1 '__UINT_LEAST8_MAX__'
1 '__UINT_LEAST16_MAX__'
1 '__UINT_LEAST32_MAX__'
1 '__UINT_LEAST64_MAX__'
1 '__INT_FAST8_MAX__'
1 '__INT_FAST16_MAX__'
1 '__INT_FAST32_MAX__'
1 '__INT_FAST64_MAX__'
1 '__UINT_FAST8_MAX__'
1 '__UINT_FAST16_MAX__'
1 '__UINT_FAST32_MAX__'
1 '__UINT_FAST64_MAX__'
1 '__INTPTR_MAX__'
1 '__UINTPTR_MAX__'
1 '__WCHAR_MIN__'
1 '__WINT_MIN__'
1 '__SIG_ATOMIC_MIN__'
1 Defined to the maximum value of the 'signed char', 'wchar_t',
1 'signed short', 'signed int', 'signed long', 'signed long long',
1 'wint_t', 'size_t', 'ptrdiff_t', 'intmax_t', 'uintmax_t',
1 'sig_atomic_t', 'int8_t', 'int16_t', 'int32_t', 'int64_t',
1 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'int_least8_t',
1 'int_least16_t', 'int_least32_t', 'int_least64_t', 'uint_least8_t',
1 'uint_least16_t', 'uint_least32_t', 'uint_least64_t',
1 'int_fast8_t', 'int_fast16_t', 'int_fast32_t', 'int_fast64_t',
1 'uint_fast8_t', 'uint_fast16_t', 'uint_fast32_t', 'uint_fast64_t',
1 'intptr_t', and 'uintptr_t' types and to the minimum value of the
1 'wchar_t', 'wint_t', and 'sig_atomic_t' types respectively. They
1 exist to make the standard header given numerical limits work
1 correctly. You should not use these macros directly; instead,
1 include the appropriate headers. Some of these macros may not be
1 defined on particular systems if GCC does not provide a 'stdint.h'
1 header on those systems.
1
1 '__INT8_C'
1 '__INT16_C'
1 '__INT32_C'
1 '__INT64_C'
1 '__UINT8_C'
1 '__UINT16_C'
1 '__UINT32_C'
1 '__UINT64_C'
1 '__INTMAX_C'
1 '__UINTMAX_C'
1 Defined to implementations of the standard 'stdint.h' macros with
1 the same names without the leading '__'. They exist the make the
1 implementation of that header work correctly. You should not use
1 these macros directly; instead, include the appropriate headers.
1 Some of these macros may not be defined on particular systems if
1 GCC does not provide a 'stdint.h' header on those systems.
1
1 '__SCHAR_WIDTH__'
1 '__SHRT_WIDTH__'
1 '__INT_WIDTH__'
1 '__LONG_WIDTH__'
1 '__LONG_LONG_WIDTH__'
1 '__PTRDIFF_WIDTH__'
1 '__SIG_ATOMIC_WIDTH__'
1 '__SIZE_WIDTH__'
1 '__WCHAR_WIDTH__'
1 '__WINT_WIDTH__'
1 '__INT_LEAST8_WIDTH__'
1 '__INT_LEAST16_WIDTH__'
1 '__INT_LEAST32_WIDTH__'
1 '__INT_LEAST64_WIDTH__'
1 '__INT_FAST8_WIDTH__'
1 '__INT_FAST16_WIDTH__'
1 '__INT_FAST32_WIDTH__'
1 '__INT_FAST64_WIDTH__'
1 '__INTPTR_WIDTH__'
1 '__INTMAX_WIDTH__'
1 Defined to the bit widths of the corresponding types. They exist
1 to make the implementations of 'limits.h' and 'stdint.h' behave
1 correctly. You should not use these macros directly; instead,
1 include the appropriate headers. Some of these macros may not be
1 defined on particular systems if GCC does not provide a 'stdint.h'
1 header on those systems.
1
1 '__SIZEOF_INT__'
1 '__SIZEOF_LONG__'
1 '__SIZEOF_LONG_LONG__'
1 '__SIZEOF_SHORT__'
1 '__SIZEOF_POINTER__'
1 '__SIZEOF_FLOAT__'
1 '__SIZEOF_DOUBLE__'
1 '__SIZEOF_LONG_DOUBLE__'
1 '__SIZEOF_SIZE_T__'
1 '__SIZEOF_WCHAR_T__'
1 '__SIZEOF_WINT_T__'
1 '__SIZEOF_PTRDIFF_T__'
1 Defined to the number of bytes of the C standard data types: 'int',
1 'long', 'long long', 'short', 'void *', 'float', 'double', 'long
1 double', 'size_t', 'wchar_t', 'wint_t' and 'ptrdiff_t'.
1
1 '__BYTE_ORDER__'
1 '__ORDER_LITTLE_ENDIAN__'
1 '__ORDER_BIG_ENDIAN__'
1 '__ORDER_PDP_ENDIAN__'
1 '__BYTE_ORDER__' is defined to one of the values
1 '__ORDER_LITTLE_ENDIAN__', '__ORDER_BIG_ENDIAN__', or
1 '__ORDER_PDP_ENDIAN__' to reflect the layout of multi-byte and
1 multi-word quantities in memory. If '__BYTE_ORDER__' is equal to
1 '__ORDER_LITTLE_ENDIAN__' or '__ORDER_BIG_ENDIAN__', then
1 multi-byte and multi-word quantities are laid out identically: the
1 byte (word) at the lowest address is the least significant or most
1 significant byte (word) of the quantity, respectively. If
1 '__BYTE_ORDER__' is equal to '__ORDER_PDP_ENDIAN__', then bytes in
1 16-bit words are laid out in a little-endian fashion, whereas the
1 16-bit subwords of a 32-bit quantity are laid out in big-endian
1 fashion.
1
1 You should use these macros for testing like this:
1
1 /* Test for a little-endian machine */
1 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1
1 '__FLOAT_WORD_ORDER__'
1 '__FLOAT_WORD_ORDER__' is defined to one of the values
1 '__ORDER_LITTLE_ENDIAN__' or '__ORDER_BIG_ENDIAN__' to reflect the
1 layout of the words of multi-word floating-point quantities.
1
1 '__DEPRECATED'
1 This macro is defined, with value 1, when compiling a C++ source
1 file with warnings about deprecated constructs enabled. These
1 warnings are enabled by default, but can be disabled with
1 '-Wno-deprecated'.
1
1 '__EXCEPTIONS'
1 This macro is defined, with value 1, when compiling a C++ source
1 file with exceptions enabled. If '-fno-exceptions' is used when
1 compiling the file, then this macro is not defined.
1
1 '__GXX_RTTI'
1 This macro is defined, with value 1, when compiling a C++ source
1 file with runtime type identification enabled. If '-fno-rtti' is
1 used when compiling the file, then this macro is not defined.
1
1 '__USING_SJLJ_EXCEPTIONS__'
1 This macro is defined, with value 1, if the compiler uses the old
1 mechanism based on 'setjmp' and 'longjmp' for exception handling.
1
1 '__GXX_EXPERIMENTAL_CXX0X__'
1 This macro is defined when compiling a C++ source file with the
1 option '-std=c++0x' or '-std=gnu++0x'. It indicates that some
1 features likely to be included in C++0x are available. Note that
1 these features are experimental, and may change or be removed in
1 future versions of GCC.
1
1 '__GXX_WEAK__'
1 This macro is defined when compiling a C++ source file. It has the
1 value 1 if the compiler will use weak symbols, COMDAT sections, or
1 other similar techniques to collapse symbols with "vague linkage"
1 that are defined in multiple translation units. If the compiler
1 will not collapse such symbols, this macro is defined with value 0.
1 In general, user code should not need to make use of this macro;
1 the purpose of this macro is to ease implementation of the C++
1 runtime library provided with G++.
1
1 '__NEXT_RUNTIME__'
1 This macro is defined, with value 1, if (and only if) the NeXT
1 runtime (as in '-fnext-runtime') is in use for Objective-C. If the
1 GNU runtime is used, this macro is not defined, so that you can use
1 this macro to determine which runtime (NeXT or GNU) is being used.
1
1 '__LP64__'
1 '_LP64'
1 These macros are defined, with value 1, if (and only if) the
1 compilation is for a target where 'long int' and pointer both use
1 64-bits and 'int' uses 32-bit.
1
1 '__SSP__'
1 This macro is defined, with value 1, when '-fstack-protector' is in
1 use.
1
1 '__SSP_ALL__'
1 This macro is defined, with value 2, when '-fstack-protector-all'
1 is in use.
1
1 '__SSP_STRONG__'
1 This macro is defined, with value 3, when
1 '-fstack-protector-strong' is in use.
1
1 '__SSP_EXPLICIT__'
1 This macro is defined, with value 4, when
1 '-fstack-protector-explicit' is in use.
1
1 '__SANITIZE_ADDRESS__'
1 This macro is defined, with value 1, when '-fsanitize=address' or
1 '-fsanitize=kernel-address' are in use.
1
1 '__SANITIZE_THREAD__'
1 This macro is defined, with value 1, when '-fsanitize=thread' is in
1 use.
1
1 '__TIMESTAMP__'
1 This macro expands to a string constant that describes the date and
1 time of the last modification of the current source file. The
1 string constant contains abbreviated day of the week, month, day of
1 the month, time in hh:mm:ss form, year and looks like
1 '"Sun Sep 16 01:03:52 1973"'. If the day of the month is less than
1 10, it is padded with a space on the left.
1
1 If GCC cannot determine the current date, it will emit a warning
1 message (once per compilation) and '__TIMESTAMP__' will expand to
1 '"??? ??? ?? ??:??:?? ????"'.
1
1 '__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1'
1 '__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2'
1 '__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4'
1 '__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8'
1 '__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16'
1 These macros are defined when the target processor supports atomic
1 compare and swap operations on operands 1, 2, 4, 8 or 16 bytes in
1 length, respectively.
1
1 '__GCC_HAVE_DWARF2_CFI_ASM'
1 This macro is defined when the compiler is emitting DWARF CFI
1 directives to the assembler. When this is defined, it is possible
1 to emit those same directives in inline assembly.
1
1 '__FP_FAST_FMA'
1 '__FP_FAST_FMAF'
1 '__FP_FAST_FMAL'
1 These macros are defined with value 1 if the backend supports the
1 'fma', 'fmaf', and 'fmal' builtin functions, so that the include
1 file 'math.h' can define the macros 'FP_FAST_FMA', 'FP_FAST_FMAF',
1 and 'FP_FAST_FMAL' for compatibility with the 1999 C standard.
1
1 '__FP_FAST_FMAF16'
1 '__FP_FAST_FMAF32'
1 '__FP_FAST_FMAF64'
1 '__FP_FAST_FMAF128'
1 '__FP_FAST_FMAF32X'
1 '__FP_FAST_FMAF64X'
1 '__FP_FAST_FMAF128X'
1 These macros are defined with the value 1 if the backend supports
1 the 'fma' functions using the additional '_FloatN' and '_FloatNx'
1 types that are defined in ISO/IEC TS 18661-3:2015. The include
1 file 'math.h' can define the 'FP_FAST_FMAFN' and 'FP_FAST_FMAFNx'
1 macros if the user defined '__STDC_WANT_IEC_60559_TYPES_EXT__'
1 before including 'math.h'.
1
1 '__GCC_IEC_559'
1 This macro is defined to indicate the intended level of support for
1 IEEE 754 (IEC 60559) floating-point arithmetic. It expands to a
1 nonnegative integer value. If 0, it indicates that the combination
1 of the compiler configuration and the command-line options is not
1 intended to support IEEE 754 arithmetic for 'float' and 'double' as
1 defined in C99 and C11 Annex F (for example, that the standard
1 rounding modes and exceptions are not supported, or that
1 optimizations are enabled that conflict with IEEE 754 semantics).
1 If 1, it indicates that IEEE 754 arithmetic is intended to be
1 supported; this does not mean that all relevant language features
1 are supported by GCC. If 2 or more, it additionally indicates
1 support for IEEE 754-2008 (in particular, that the binary encodings
1 for quiet and signaling NaNs are as specified in IEEE 754-2008).
1
1 This macro does not indicate the default state of command-line
1 options that control optimizations that C99 and C11 permit to be
1 controlled by standard pragmas, where those standards do not
1 require a particular default state. It does not indicate whether
1 optimizations respect signaling NaN semantics (the macro for that
1 is '__SUPPORT_SNAN__'). It does not indicate support for decimal
1 floating point or the IEEE 754 binary16 and binary128 types.
1
1 '__GCC_IEC_559_COMPLEX'
1 This macro is defined to indicate the intended level of support for
1 IEEE 754 (IEC 60559) floating-point arithmetic for complex numbers,
1 as defined in C99 and C11 Annex G. It expands to a nonnegative
1 integer value. If 0, it indicates that the combination of the
1 compiler configuration and the command-line options is not intended
1 to support Annex G requirements (for example, because
1 '-fcx-limited-range' was used). If 1 or more, it indicates that it
1 is intended to support those requirements; this does not mean that
1 all relevant language features are supported by GCC.
1
1 '__NO_MATH_ERRNO__'
1 This macro is defined if '-fno-math-errno' is used, or enabled by
1 another option such as '-ffast-math' or by default.
1