Next: System-specific Predefined Macros, Previous: Standard Predefined Macros, Up: Predefined Macros
3.7.2 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 underscores.
__GNUC____GNUC_MINOR____GNUC_PATCHLEVEL__- 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. These macros are also defined if you invoke the preprocessor directly.__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 have).If all you need to know is whether or not your program is being compiled by GCC, or a non-GCC compiler that claims to accept the GNU C dialects, 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 && \ __GNUC_PATCHLEVEL__ > 0))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 \ + __GNUC_PATCHLEVEL__) ... /* Test for GCC > 3.2.0 */ #if GCC_VERSION > 30200Many people find this form easier to understand.
__GNUG__- The GNU C++ compiler defines this. Testing it is equivalent to
testing
(__GNUC__ && __cplusplus). __STRICT_ANSI__- 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
standard.
__BASE_FILE__- 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.
__INCLUDE_LEVEL__- 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.
__ELF__- This macro is defined if the target uses the ELF object format.
__VERSION__- 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.
__PIC__- This macro is defined when gcc is generating pic code for darwin.
__OPTIMIZE____OPTIMIZE_SIZE____NO_INLINE__- 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.
__GNUC_GNU_INLINE__- GCC defines this macro if functions declared
inlinewill be handled in GCC's traditional gnu89 mode. In this mode anextern inlinefunction will never be compiled as a standalone function, and aninlinefunction which is neitherexternnorstaticwill always be compiled as a standalone function. __GNUC_STDC_INLINE__- GCC defines this macro if functions declared
inlinewill be handled according to the ISO C99 standard. In this mode anextern inlinefunction will always be compiled as a standalone externally visible function, and aninlinefunction which is neitherexternnorstaticwill never be compiled as a standalone function.If this macro is defined, GCC supports the
gnu_inlinefunction attribute as a way to always get the gnu89 behaviour. Support for this and__GNUC_GNU_INLINE__was added in GCC 4.1.3. If neither macro is defined, an older version of GCC is being used:inlinefunctions will be compiled in gnu89 mode, and thegnu_inlinefunction attribute will not be recognized. __CHAR_UNSIGNED__- GCC defines this macro if and only if the data type
charis 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 limits.h. __WCHAR_UNSIGNED__- Like
__CHAR_UNSIGNED__, this macro is defined if and only if the data typewchar_tis unsigned and the front-end is in C++ mode. __REGISTER_PREFIX__- 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-aoutenvironment it expands to nothing, but in them68k-coffenvironment it expands to a single `%'. __USER_LABEL_PREFIX__- 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-aoutenvironment it expands to an `_', but in them68k-coffenvironment 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).
__SIZE_TYPE____PTRDIFF_TYPE____WCHAR_TYPE____WINT_TYPE____INTMAX_TYPE____UINTMAX_TYPE__- These macros are defined to the correct underlying types for the
size_t,ptrdiff_t,wchar_t,wint_t,intmax_t, anduintmax_ttypedefs, 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. __CHAR_BIT__- Defined to the number of bits used in the representation of the
chardata type. It exists to make the standard header given numerical limits work correctly. You should not use this macro directly; instead, include the appropriate headers. __SCHAR_MAX____WCHAR_MAX____SHRT_MAX____INT_MAX____LONG_MAX____LONG_LONG_MAX____INTMAX_MAX__- Defined to the maximum value of the
signed char,wchar_t,signed short,signed int,signed long,signed long long, andintmax_ttypes respectively. They exist to make the standard header given numerical limits work correctly. You should not use these macros directly; instead, include the appropriate headers. __DEPRECATED- This macro is defined, with value 1, when compiling a C++ source file
with warnings about deprecated constructs enabled. These warnings are
enabled by default, but can be disabled with -Wno-deprecated.
__EXCEPTIONS- This macro is defined, with value 1, when compiling a C++ source file
with exceptions enabled. If -fno-exceptions was used when
compiling the file, then this macro will not be defined.
__USING_SJLJ_EXCEPTIONS__- This macro is defined, with value 1, if the compiler uses the old
mechanism based on
setjmpandlongjmpfor exception handling. __GXX_WEAK__- This macro is defined when compiling a C++ source file. It has the
value 1 if the compiler will use weak symbols, COMDAT sections, or
other similar techniques to collapse symbols with “vague linkage”
that are defined in multiple translation units. If the compiler will
not collapse such symbols, this macro is defined with value 0. In
general, user code should not need to make use of this macro; the
purpose of this macro is to ease implementation of the C++ runtime
library provided with G++.
__NEXT_RUNTIME__- This macro is defined, with value 1, if (and only if) the NeXT runtime
(as in -fnext-runtime) is in use for Objective-C. If the GNU
runtime is used, this macro is not defined, so that you can use this
macro to determine which runtime (NeXT or GNU) is being used.
__LP64___LP64- These macros are defined, with value 1, if (and only if) the compilation
is for a target where
long intand pointer both use 64-bits andintuses 32-bit. __SSP__- This macro is defined, with value 1, when -fstack-protector is in
use.
__SSP_ALL__- This macro is defined, with value 2, when -fstack-protector-all is
in use.
__TIMESTAMP__- This macro expands to a string constant that describes the date and time
of the last modification of the current source file. The string constant
contains abbreviated day of the week, month, day of the month, time in
hh:mm:ss form, year and looks like
"Sun Sep 16 01:03:52 1973". If the day of the month is less than 10, it is padded with a space on the left.If GCC cannot determine the current date, it will emit a warning message (once per compilation) and
__TIMESTAMP__will expand to"??? ??? ?? ??:??:?? ????".