| __GNUC__

| Common Predefined Macros | Next

This macro is always defined in GCC. The value identifies the GCC major version number (currently '3').
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 && \
                            __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.

See also: __GNUC_MINOR__, __GNUC_PATCHLEVEL__