Common Predefined Macros - Red Hat ENTERPRISE LINUX 3 - USING CPP Using Instructions

Using cpp, the c preprocessor
Hide thumbs Also See for ENTERPRISE LINUX 3 - USING CPP:
Table of Contents

Advertisement

Chapter 3. 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
2, and
__GNUC_PATCHLEVEL__
if you invoke the preprocessor directly, they are not defined.
__GNUC_PATCHLEVEL__
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, you can
simply test
__GNUC__
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
#if __GNUC__
(__GNUC__ == 3 && (__GNUC_MINOR__
Another approach is to use the predefined macros to calculate a single number, then compare that
against a threshold:
#define GCC_VERSION (__GNUC__ * 10000 \
...
/* Test for GCC
#if GCC_VERSION
Many people find this form easier to understand.
__OBJC__
This macro is defined, with value 1, when the Objective-C compiler is in use. You can use
to test whether a header is compiled by a C compiler or a Objective-C compiler.
__OBJC__
__GNUG__
The GNU C++ compiler defines this. Testing it is equivalent to testing
__cplusplus)
__STRICT_ANSI__
GCC defines this macro if and only if the
conformance to some version of ISO C, was specified when GCC was invoked. It is defined to
. This macro exists primarily to direct GNU libc's header files to restrict their definitions to the
1
minimal set found in the 1989 C standard.
to 1. They are defined only when the entire compiler is in use;
is new to GCC 3.0; it is also present in the widely-used development
. If you need to write code which depends on a specific version, you must

3.2.0 */

3 || \
(__GNUC_MINOR__ == 2 && \
__GNUC_PATCHLEVEL__
+ __GNUC_MINOR__ * 100 \
+ __GNUC_PATCHLEVEL__)

3.2.0 */

30200
.
__GNUC__

2 || \

0))
switch, or a
-ansi
to 3,
__GNUC_MINOR__
(__GNUC__ &&
switch specifying strict
-std
23
to

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ENTERPRISE LINUX 3 - USING CPP and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Enterprise linux 3

Table of Contents