Next: System-specific Predefined Macros, Previous: Standard Predefined Macros, Up: 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 or GNU Fortran. Their names all start with double underscores.
__COUNTER__
##
operator, this provides a convenient means to
generate unique identifiers. Care must be taken to ensure that
__COUNTER__
is not expanded prior to inclusion of precompiled headers
which use it. Otherwise, the precompiled headers will not be used.
__GFORTRAN__
__GNUC__
__GNUC_MINOR__
__GNUC_PATCHLEVEL__
__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 > 30200
Many people find this form easier to understand.
__GNUG__
(__GNUC__ && __cplusplus)
.
__STRICT_ANSI__
__BASE_FILE__
__INCLUDE_LEVEL__
__ELF__
__VERSION__
__OPTIMIZE__
__OPTIMIZE_SIZE__
__NO_INLINE__
__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__
inline
will be
handled in GCC's traditional gnu89 mode. Object files will contain
externally visible definitions of all functions declared inline
without extern
or static
. They will not contain any
definitions of any functions declared extern inline
.
__GNUC_STDC_INLINE__
inline
will be
handled according to the ISO C99 standard. Object files will contain
externally visible definitions of all functions declared extern
inline
. They will not contain definitions of any functions declared
inline
without extern
.
If this macro is defined, GCC supports the gnu_inline
function
attribute as a way to always get the gnu89 behavior. 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:
inline
functions will be compiled in gnu89 mode, and the
gnu_inline
function attribute will not be recognized.
__CHAR_UNSIGNED__
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 limits.h.
__WCHAR_UNSIGNED__
__CHAR_UNSIGNED__
, this macro is defined if and only if the
data type wchar_t
is unsigned and the front-end is in C++ mode.
__REGISTER_PREFIX__
m68k-aout
environment it
expands to nothing, but in the m68k-coff
environment it expands
to a single %.
__USER_LABEL_PREFIX__
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).
__SIZE_TYPE__
__PTRDIFF_TYPE__
__WCHAR_TYPE__
__WINT_TYPE__
__INTMAX_TYPE__
__UINTMAX_TYPE__
size_t
, ptrdiff_t
, wchar_t
, wint_t
,
intmax_t
, and uintmax_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.
__CHAR_BIT__
char
data 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__
signed char
, wchar_t
,
signed short
,
signed int
, signed long
, signed long long
, and
intmax_t
types
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.
__SIZEOF_INT__
__SIZEOF_LONG__
__SIZEOF_LONG_LONG__
__SIZEOF_SHORT__
__SIZEOF_POINTER__
__SIZEOF_FLOAT__
__SIZEOF_DOUBLE__
__SIZEOF_LONG_DOUBLE__
__SIZEOF_SIZE_T__
__SIZEOF_WCHAR_T__
__SIZEOF_WINT_T__
__SIZEOF_PTRDIFF_T__
int
,
long
, long long
, short
, void *
, float
,
double
, long double
, size_t
, wchar_t
, wint_t
and ptrdiff_t
.
__DEPRECATED
__EXCEPTIONS
__GXX_RTTI
__USING_SJLJ_EXCEPTIONS__
setjmp
and longjmp
for exception
handling.
__GXX_EXPERIMENTAL_CXX0X__
__GXX_WEAK__
__NEXT_RUNTIME__
__LP64__
_LP64
long int
and pointer both use 64-bits and
int
uses 32-bit.
__SSP__
__SSP_ALL__
__TIMESTAMP__
"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
"??? ??? ?? ??:??:?? ????"
.
__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16