Intel® Fortran Compiler 17.0 Developer Guide and Reference
The Fortran compiler 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 Using Predefined Preprocessor Symbols.
fpp has some of the capabilities of the ANSI C preprocessor and supports a similar set of preprocessor directives. Preprocessor 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 preprocessor directives is based on that of the C preprocessor.
The compiler includes a limited conditional compilation capability, based on directives, that does not require use of fpp. The IF directive construct provides the capability of limited conditional compilation.
Note that you can also specify an alternate Fortran preprocessor instead of the Intel® Fortran fpp preprocessor. For more information, see option fpp-name.
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 the .fpp, .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-form and fixed-form Fortran source files. By default, filenames with the suffix of .F, .f, .for, or .fpp are assumed to be 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 compiler option to specify free form and the fixed compiler option to explicitly specify fixed form.
The fpp preprocessor recognizes tab format in a source line in fixed form.
You can explicitly run fpp in these ways:
On the ifort command line, use the ifort command with the fpp compiler option. By default, the specified files are then compiled and linked. To retain the intermediate (.i or .i90) file, specify the [Q]save-temps compiler option.
On the command line, use the fpp command. In this case, the compiler is not invoked. When using the fpp command line, you need to specify the input file and the intermediate (.i or .i90) output file. For more information, type fpp -help (Linux and OS X) or fpp /help (Windows) on the command line.
In the Microsoft Visual Studio* IDE, set the Preprocess Source File option to Yes in the Fortran Preprocessor Option Category. To retain the intermediate files, add /Qsave-temps to Additional Options in the Fortran Command Line Category.
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 and #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.
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.
A source file can contain fpp tokens in the following forms:
fpp preprocessor directive names
For more information on fpp preprocessor directives, see Using fpp Preprocessor Directives.
symbolic names including Fortran keywords
fpp permits the same characters in names as Fortran. For more information on symbolic names, see Using Predefined Preprocessor Symbols.
constants
Integer, real, double, and quadruple precision real, binary, octal, hexadecimal (including alternate notation), character, and Hollerith constants are allowed.
special characters, space, tab, and newline characters
comments, including:
Fortran language comments. A fixed form source line containing one of the symbols C, c, *, d, or D in the first position is considered a comment line. The ! symbol is interpreted as the beginning of a comment extending to the end of the line except when the ! occurs within a constant-expression in an #if or #elif directive. Within such comments, macro expansions are not performed, but they can be switched on by -f-com=no.
fpp comments between /* and */. They are excluded from the output and macro expansions are not performed within these symbols. fpp comments can be nested: for each /* there must be a corresponding */. fpp comments are useful for excluding from the compilation large portions of source instead of commenting every line with a Fortran comment symbol.
C++ -like line comments that begin with // (double-slash).
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.
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 preprocessor option P to disable the generation of these lines.
There are three kinds of fpp diagnostic messages:
warnings: preprocessing of source code is continued and the fpp return value is 0
errors: fpp continues preprocessing but sets the return value to a nonzero value which is the number of errors
fatal errors: fpp stops preprocessing and returns a nonzero return value.
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.