Intel® Fortran Compiler 17.0 Developer Guide and Reference

Using fpp Preprocessor Directives

All fpp preprocessor 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 preprocessor directives can be placed anywhere in source code, in particular before a Fortran continuation line. However, fpp preprocessor directives within a macro call can not be divided among several lines by means of continuation symbols.

fpp preprocessor directives can be grouped according to their purpose.

Preprocessor directives for string substitution

The following fpp preprocessor directives cause substitutions in your program:

Preprocessor Directive

Result

__FILE__

Replaces a string with the input file name (a character string literal).

__LINE__

Replaces a string with the current line number in the input file (an integer constant).

__DATE__

Replaces a string with the date that fpp processed the input file (a character string literal in the form Mmm dd yyyy).

__TIME__

Replaces a string with the time that fpp processed the input file (a character string literal in the form hh:mm:ss).

__TIMESTAMP__

Replaces a 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).

Preprocessor directive for inclusion of external files

To include external files, preprocessor directive #include can be specified in one of the following forms:

#include "filename"
#include <filename>

#include reads in the contents of the named file into the specified or default 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. For more information, 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 ">".

For #include "filename", filenames are searched for in the following order:

For #include <filename>, filenames are searched for in the following order:

Preprocessor directive for line control

The preprocessor directive #line-number generates line control information for the Fortran compiler. It takes the following form:

#line-number "filename"

#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.

Preprocessor directive for fpp variable and macro definitions

The preprocessor directive #define can be used to define both simple string variables and more complicated macros. It can take two forms.

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:

Preprocessor directive for undefining a macro

The preprocessor directive #undef takes the following form:

#undef name

This preprocessor directive removes any definition for name produced by the D options, the #define preprocessor directives, or by default. No additional tokens are permitted on the directive line after name.

If name has not been previously defined, then #undef has no effect.

Preprocessor directive for macro expansion

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):

In fixed format, when the fpp option-Xw 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 callp token sequence above. It could be considered to be a macro name. The current implementation does the following:

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 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.

Preprocessor directives for conditional selection of source text

The following three preprocessor directives are conditional constructs that you can use to select source text.

The #else, #elif, or #endif preprocessor directives are optional. They can be used in the above preprocessor directives.

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.

Conditional expressions

condition_1, condition_2, etc. are logical expressions involving fpp constants, macros, and intrinsic functions. The following items are permitted in conditional expressions:

#ifdef is shorthand for #if defined(name) and #ifndef is 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 preprocessor directive, or defined by default, has a value of 0. The C operation != (not equal) can be used in the #if or #elif preprocessor directive, but not in the #define preprocessor directive, where the symbol ! is considered to be the Fortran comment symbol by default.

See Also