Macro definition and application
The full scope of the macro facility can only be appreciated with some
knowledge of how RFPP stores, retrieves and expands macro definitions. There
are two fundamental macro operations; the macro definition and the macro
invocation. The macro definition is achieved via the inbuilt macro: command,
and the invocation occurs when the macro name is subsequently used in the
code.
The macro: command stores the macro name and definition in the RFPP macro
table and sets various pointers for its efficient extraction. The macro
definition process is performed in two separate steps. The first occurs when
the macro: instruction is encountered and the definition string is stored in
the RFPP macro table, and the second when the string is placed in the Fortran
output. During both these steps the definition is searched for any macro names
and these are 'expanded' (i.e. the name is replaced by the definition) provided
the appropriate definitions exist in the macro table. In other words the
preprocessor has two (and only two!) opportunities to substitute the macro
definition for a macro name. If a macro definition is not available by step
two, the macro name is output into the Fortran.
Occasionally, it is necessary to prevent macro expansion during step 1, and in
special circumstances even during step 2. In these cases macro expansion can be
prevented by surrounding the definition with either square brackets or
apostrophes. Understanding the function of macro expansion inhibitors is
important for the advanced use of this facility.
|