Intel® Fortran Compiler 16.0 User and Reference Guide
All fpp directives start with the number sign (#) as the first character on a line. White space (blank or tab characters) can appear after the initial "#" for indentation.
fpp directives (beginning with the # symbol in the first position of lines) can be placed anywhere in a source code, in particular before a Fortran continuation line. However, fpp directives within a macro call may not be divided among several lines by means of continuation symbols.
fpp directives can be grouped according to their purpose.
fpp contains directives that result in substitutions in a user's program:
Directive |
Result |
---|---|
__FILE__ |
Replaces this string with the input file name (a character string literal). |
__LINE__ |
Replaces this string with the current line number in the input file (an integer constant). |
__DATE__ |
Replaces this string with the date that fpp processed the input file (a character string literal in the form Mmm dd yyyy). |
__TIME__ |
Replaces this string with the time that fpp processed the input file (a character string literal in the form hh:mm:ss). |
__TIMESTAMP__ |
Replaces this string with the timestamp that fpp processed the input file (a character string literal in the form "day date time year", where day is a 3-letter abbreviation, date is Mmm dd, time is hh:mm:ss and year is yyyy). |
There are two forms of file inclusion:
#include "filename"
#include <filename>
This directive reads in the contents of the named file into this location in the source. The lines read in from the file are processed by fpp just as if they were part of the current file.
When the <filename> notation is used, filename is only searched for in the standard "include" directories. See the fpp -I and the -Y options in Using Fortran Preprocessor Options. No additional tokens are allowed on the directive line after the final '"' or ">".
Files are searched for in the following order:
for #include "filename":
in the directory in which the source file resides
in the directories specified by the -I or -Y option
in the default directory
for #include <filename>:
in the directories specified by the -I or -Y option
in the default directory
This directive takes the following form:
#line-number "filename"
This directive generates line control information for the Fortran compiler. line-number is an integer constant that is the line number of the next line. "filename" is the name of the file containing the line. If "filename" is not provided, the current filename is assumed.
The #define directive, used to define both simple string variables and more complicated macros, takes the two forms.
The first form is the definition of an fpp variable:
#define name token-string
In the above, occurrences of name in the source file will be substituted with token-string.
The second form is the definition of an fpp macro.
#define name(argument[,argument] ... ) token-string
In the above, occurrences of the macro name followed by the comma-separated list of actual arguments within parentheses are replaced by token-string with each occurrence of each argument in token-string replaced by the token sequence representing the corresponding "actual" argument in the macro call.
An error is produced if the number of macro call arguments is not the same as the number of arguments in the corresponding macro definition. For example, consider this macro definition:
#define INTSUB(m, n, o) call mysub(m, n, o)
Any use of the macro INTSUB must have three arguments. In macro definitions, spaces between the macro name and the open parenthesis "(" are prohibited to prevent the directive from being interpreted as an fpp variable definition with the rest of the line beginning with the open parenthesis "(" being interpreted as its token-string.
An fpp variable or macro definition can be of any length and is limited only by the newline symbol. It can be defined in multiple lines by continuing it to the next line with the insertion of "\". The occurrence of a newline without a macro-continuation signifies the end of the macro definition.
Example:
#define long_macro_name(x,\ y) x*y
The scope of a definition begins from the #define and encloses all the source lines (and source lines from #include files) to the end of the current file, except for:
files included by Fortran INCLUDE statements
fpp and Fortran comments
Fortran IMPLICIT statements that specify a single letter
Fortran FORMAT statements
numeric, typeless, and character constants
This directive takes the following form:
#undef name
This directive removes any definition for name (produced by the D options, #define directives, or by default). No additional tokens are permitted on the directive line after name.
If name has not been defined earlier, then the #undef directive has no effect.
If, during expansion of a macro, the column width of a line exceeds column 72 (for fixed format) or column 132 (for free format), fpp inserts appropriate Fortran continuation lines.
For fixed format, there is a limit on macro expansions in label fields (positions 1-5):
a macro call (together with possible arguments) should not extend beyond column 5
a macro call whose name begins with one of the Fortran comment symbols is considered to be part of a comment
a macro expansion may produce text extending beyond column 5. In this case, a warning will be issued
In fixed format, when the fpp -Xw option has been specified, an ambiguity may occur if a macro call occurs in a statement position and a macro name begins or coincides with a Fortran keyword. For example, consider the following:
#define callp(x) call f(x) call p(0)
fpp cannot determine how to interpret the "call p" token sequence above. It could be considered as a macro name. The current implementation does the following:
the longer identifier is chosen (callp in this case)
from this identifier the longest macro name or keyword is extracted
if a macro name has been extracted a macro expansion is performed. If the name begins with some keyword, fpp issues an appropriate warning
the rest of the identifier is considered as a whole identifier
In the previous example, the macro expansion is performed and the following warning is produced:
warning: possibly incorrect substitution of macro callp
This situation appears only when preprocessing a fixed format source code and when the space symbol is not interpreted as a token delimiter.
In the following case, a macro name coincides with a beginning of a keyword:
#define INT INTEGER*8 INTEGER k
The INTEGER keyword will be found earlier than the INT macro name. There will be no warning when preprocessing such a macro definition.
There are three forms of conditional selection of source text.
Form 1:
#if condition_1 block_1 #elif condition_2 block_2 #elif ... #else block_n #endif
Form 2:
#ifdefname block_1 #elif condition block_2 #elif ... #else block_n #endif
Form 3:
#ifndef name block_1 #elif condition block_2 #elif ... #else block_n #endif
The #elif and #else parts are optional in all three forms. There can be more than one #elif part in each form.
Conditional expressions
condition_1, condition_2, etc. are logical expressions involving fpp constants, macros, and intrinsic functions. The following items are permitted:
C language operations: <, >, ==, !=, >=, <=, +, -, /, *, %, <<, >>, &, ~, |, &&, || They are interpreted by fpp in accordance to the C language semantics (this facility is provided for compatibility with "old" Fortran programs using cpp)
Fortran language operations: .AND., .OR., .NEQV., .XOR., .EQV., .NOT., .GT., .LT., .LE., .GE., .NE., .EQ., ** (power).
Fortran logical constants: .TRUE. , .FALSE.
the fpp intrinsic function "defined": defined(name) or defined name which returns .TRUE. if name is defined as an fpp variable or a macro or returns .FALSE. if the name is not defined
#ifdef is a shorthand for #if defined(name) and #ifndef is a shorthand for #if .not. defined(name).
Only these items, integer constants, and names can be used within a constant-expression. A name that has not been defined with the -D option, a #define directive, or by default, has a value of 0. The C operation != (not equal) can be used in the #if or #elif directive, but not in the #define directive, where the symbol ! is considered to be the Fortran comment symbol by default.
Conditional constructs
The following table summarizes conditional constructs.
Construct |
Result |
---|---|
#if condition |
Subsequent lines up to the matching #else, #elif, or #endif directive appear in the output only if condition evaluates to .TRUE.. |
#ifdef name |
Subsequent lines up to the matching #else, #elif, or #endif appear in the output only if name has been defined, either by a #define directive or by the D compiler option, with no intervening #undef directive. No additional tokens are permitted on the directive line after name. |
#ifndef name |
Subsequent lines up to the matching #else, #elif, or #endif appear in the output only if name has not been defined, or if its definition has been removed with an #undef directive. No additional tokens are permitted on the directive line after name. |
#elif condition |
Subsequent lines up to the matching #else, #elif, or #endif appear in the output only if all of the following occur:
Any condition allowed in an #if directive is allowed in an #elif directive. Any number of #elif directives may appear between an #if, #ifdef, or #ifndef directive and a matching #else or #endif directive. |
#else |
Subsequent lines up to the matching #endif appear in the output only if all of the following occur:
|
#endif |
End a section of lines begun by one of the conditional directives #if, #ifdef, or #ifndef. Each such directive must have a matching #endif. |