Using the fpp Preprocessor

If you choose to preprocess your source programs, you can use the preprocessor fpp, which is the preprocessor supplied with the Intel® Fortran Compiler, or the preprocessing directives capability of the Fortran compiler. It is recommended that you use fpp.

The Fortran preprocessor, fpp, is provided as part of the Intel® Fortran product. When you use a preprocessor for Intel Fortran source files, the generated output files are used as input source files by the Compiler.

Preprocessing performs such tasks as preprocessor symbol (macro) substitution, conditional compilation, and file inclusion. Intel Fortran predefined symbols are described in Predefined Preprocessor Symbols.

The Compiler Options reference provides syntactical information on fpp. Additionally, it contains a list of fpp options that are available when fpp is in effect.

Automatic Preprocessing by the Compiler

By default, the preprocessor is not run on files before compilation. However, the Intel Fortran compiler automatically calls fpp when compiling source files that have a filename extension of .fpp, and, on Linux* OS and Mac OS* X, file extensions of .F, .F90, .FOR, .FTN, or .FPP. For example, the following command preprocesses a source file that contains fpp preprocessor directives, then passes the preprocessed file to the compiler and linker:

ifort source.fpp

If you want to preprocess files that have other Fortran extensions than those listed, you have to explicitly specify the preprocessor with the -fpp compiler option.

The fpp preprocessor can process both free- and fixed-form Fortran source files. By default, filenames with the suffix of .F, .f, .for, or .fpp are assumed to be in fixed form. Filenames with a suffix of .F90 or .f90 (or any other suffix not specifically mentioned here) are assumed to be free form. You can use the -free (Linux OS and Mac OS X) or /free (Windows* OS) option to specify free form and the -fixed (Linux OS and Mac OS X) or /fixed (Windows OS) option to explicitly specify fixed form.

The fpp preprocessor recognizes tab format in a source line in fixed form.

Running fpp to Preprocess Files

You can explicitly run fpp in these ways:

fpp has some of the capabilities of the ANSI C preprocessor and supports a similar set of directives. Directives must begin in column 1 of any Fortran source files.Preprocessor directives are not part of the Fortran language and not subject to the rules for Fortran statements. Syntax for directives is based on that of the C preprocessor.

The following lists some common cpp features that are supported by fpp; it also shows common cpp features that are not supported.

Supported cpp features:

Unsupported cpp features:

#define, #undef, #ifdef, #ifndef, #if, #elif, #else, #endif, #include, #error, #warning, #line

#pragma, #ident

# (stringsize) and ## (concatenation) operators

spaces or tab characters preceding the initial "#" character

# followed by empty line

! as negation operator

\ backslash-newline

Unlike cpp, fpp does not merge continued lines into a single line when possible.

You do not usually need to specify preprocessing for Fortran source programs unless your program uses fpp preprocessing commands, such as those listed above.

Caution iconCaution

Using a preprocessor that does not support Fortran can damage your Fortran code, especially with FORMAT (\\I4) with cpp changes the meaning of the program because the double backslash "\\" indicates end-of-record with most C/C++ preprocessors.

fpp Source Files

A source file can contain fpp tokens in the form of :

A string that is a token can occupy several lines, but only if its input includes continued line characters using the Fortran continuation character &. fpp will not merge such lines into one line.

Identifiers are always placed on one line by fpp. For example, if an input identifier occupies several lines, it will be merged by fpp into one line.

fpp Output

Output consists of a modified copy of the input, plus lines of the form:

#line_number file_name

These are inserted to indicate the original source line number and filename of the output line that follows. Use the fpp option -P (Linux OS and Mac OS X) or /P (Windows OS) to disable the generation of these lines.

Diagnostics

There are three kinds of fpp diagnostic messages:

The messages produced by fpp are intended to be self-explanatory. The line number and filename where the error occurred are displayed along with the diagnostic on stderr.