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 preprocessingdirectivescapability 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 inPredefined 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 afilename extensionof .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-fppcompiler 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:
• On theifortcommand line, use theifortcommand with the -fpp(Linux OS and Mac OS X) or/fpp(Windows OS) option. By default, the specified files are then compiled and linked. To retain the intermediate (.i or .i90) file, specify the-save-temps(Linux OS and Mac OS X) or/Qsave-temps(Windows OS) 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, typefpp -help(Linux OS and Mac OS X) or fpp
/help(Windows OS) 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.
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.
Unsupported cpp features: Supported cpp features:
#pragma, #ident #define, #undef, #ifdef, #ifndef, #if, #elif, #else,
#endif, #include, #error, #warning, #line
spaces or tab characters preceding the initial "#" character
# (stringsize) and ## (concatenation) operators
# followed by empty line \ backslash-newline ! as negation operator
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. Using a preprocessor that does not support Fortran can damage your Fortran
code, especially withFORMAT (\\I4)with cpp changes the meaning of the program because thedoublebackslash "\\" indicates end-of-record with most C/C++ preprocessors.
fpp Source Files
A source file can contain fpp tokens in the form of :
• fpp directive names. For more information on directives, seeUsing fpp Directives.
• symbolic names including Fortran keywords. fpp permits the same characters in names as Fortran. For more information on symbolic names, seeUsing 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 a #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 which 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.
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:
• warnings: preprocessing of source code is continued and the fpp return value is 0
• errors: fpp continues preprocessing but sets the return value 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.