Many Fortran compilers including GNU Fortran allow passing the source code through a C preprocessor (CPP; sometimes also called the Fortran preprocessor, FPP) to allow for conditional compilation. In the case of GNU Fortran, this is the GNU C Preprocessor in the traditional mode. On systems with case-preserving file names, the preprocessor is automatically invoked if the filename extension is .F, .FOR, .FTN, .fpp, .FPP, .F90, .F95, .F03 or .F08. To manually invoke the preprocessor on any file, use -cpp, to disable preprocessing on files where the preprocessor is run automatically, use -nocpp.
If a preprocessed file includes another file with the Fortran INCLUDE
statement, the included file is not preprocessed. To preprocess included
files, use the equivalent preprocessor statement #include
.
If GNU Fortran invokes the preprocessor, __GFORTRAN__
is defined and __GNUC__
, __GNUC_MINOR__
and
__GNUC_PATCHLEVEL__
can be used to determine the version of the
compiler. See Overview for details.
While CPP is the de-facto standard for preprocessing Fortran code, Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines Conditional Compilation, which is not widely used and not directly supported by the GNU Fortran compiler. You can use the program coco to preprocess such files (http://www.daniellnagle.com/coco.html).