Fortran Wiki
Predefined preprocessor macros

Fortran compilers that support fpp or cpp generally define preprocessor macros that can be used to adapt code based on compiler-dependent features.

Below are examples for some compilers that support fpp or cpp. Eventually, this could be expanded to show values for different host architectures and compilation options. For example, a compiler may define _OPENMP when compiled to support OpenMP.

Unfortunately, there is no common convention for the information supplied, and they do not define the Fortran language revision.

Gnu Fortran (gfortran)

Uses a built-in cpp in traditional mode with the flag -cpp. You can determine the predefined macros by using the preprocess-only flag -E and the cpp flag -dM, for example:

gfortran -cpp -E -dM empty.f90

The following macros are predefined in version 4.8 on x86_64-linux-gnu (sorted alphabetically):

#define __ATOMIC_ACQ_REL 4
#define __ATOMIC_ACQUIRE 2
#define __ATOMIC_CONSUME 1
#define __ATOMIC_RELAXED 0
#define __ATOMIC_RELEASE 3
#define __ATOMIC_SEQ_CST 5
#define __BIGGEST_ALIGNMENT__ 16
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
#define __CHAR_BIT__ 8
#define __FINITE_MATH_ONLY__ 0
#define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__
#define __GFORTRAN__ 1
#define __GNUC__ 4
#define __GNUC_MINOR__ 8
#define __GNUC_PATCHLEVEL__ 5
#define _LANGUAGE_FORTRAN 1
#define __LP64__ 1
#define _LP64 1
#define __ORDER_BIG_ENDIAN__ 4321
#define __ORDER_LITTLE_ENDIAN__ 1234
#define __ORDER_PDP_ENDIAN__ 3412
#define __SIZEOF_DOUBLE__ 8
#define __SIZEOF_FLOAT__ 4
#define __SIZEOF_INT__ 4
#define __SIZEOF_LONG__ 8
#define __SIZEOF_LONG_DOUBLE__ 16
#define __SIZEOF_LONG_LONG__ 8
#define __SIZEOF_POINTER__ 8
#define __SIZEOF_SHORT__ 2
#define __SIZEOF_SIZE_T__ 8
#define __STDC_HOSTED__ 0
#define __VERSION__ "4.8.5"

Intel Fortran (ifort / ifx)

Invokes fpp externally when given the option -fpp or -cpp. You can determine the predefined macros via:

ifx -E -fpp empty.f90 -dryrun 2>&1 | perl -lne 'print for /-D(\S+)/'

The following macros are predefined:

#define __INTEL_COMPILER 1100
#define __INTEL_COMPILER_BUILD_DATE 20081105
#define _MT 1
#define __ELF__ 1
#define __PTRDIFF_TYPE__ long
#define __SIZE_TYPE__ unsigned long
#define __WCHAR_TYPE__ int
#define __WINT_TYPE__ unsigned int
#define __INTMAX_TYPE__ long int
#define __UINTMAX_TYPE__ long unsigned int
#define __LONG_MAX__ 9223372036854775807L
#define __unix__ 1
#define __unix 1
#define __linux__ 1
#define __linux 1
#define __gnu_linux__ 1
#define unix 1
#define linux 1
#define __x86_64 1
#define __x86_64__ 1

Sun Fortran (sunf95)

Invokes fpp externally when given the option -fpp. It can also invoke an external cpp. The following macros are predefined:

#define __SUNPRO_F90 0x830
#define __SUNPRO_F95 0x830
#define unix 1
#define __unix 1
#define __unix__ 1
#define __linux 1
#define __linux__ 1
#define linux 1
#define __gnu__linux__ 1
#define i386 1
#define __i386 1