Macros within square brackets
The square brackets [ and ] have a special function within a macro definition.
The preprocessor first attempts to expand a macro definition when it is stored
in the macro table, and then again when it is subsequently invoked. Each level
of square brackets protects the macro definition from one level of expansion.
One pair of square brackets means that a macro definition is not expanded when
stored in the macro table, but is expanded when invoked. Two levels of square
brackets prevents macro expansion from taking place at all. For example, if
the definitions are in the order
macro:(nb:,10)
macro:(maxb:,arith:(5,*,nb:))
the definition of maxb: is stored in the RFPP macro table as 50.
Alternatively, if the order of macros is
macro:(maxb:,[arith:(5,*,nb:)])
macro:(nb:,10)
the definition of maxb: is stored as the string ARITH:(5,*,NB:) in the macro
table. It will be output into the Fortran code as 50.
In another example, the macro definition
macro:(defn:,[[maxmax:]])
would be stored in the macro table as [MAXMAX:]
and when
invoked it would be output in the Fortran as MAXMAX:
. In this case
the string maxmax:
is not treated as a macro.
This sequence of definitions will be processed as follows.
macro:(firstname:,bill)
macro:(fullname:,firstname:$B lastname:)
macro:(lastname:,jones)
The macro firstname:
will be stored in the macro table
as BILL
. The macro
fullname:
will be stored as BILL lastname:
since
lastname:
is not yet defined.
The macro lastname:
will be stored as JONES
.
When the macro fullname:
appears
in the ratmac code, the definition string is scanned again and the macro
definition of lastname:
is inserted. The string BILL JONES
is inserted into the Fortran code.
For this sequence, the use of square brackets is essential.
macro:(nbyte:,4)
macro:(length:,arith:(nword:,*,nbyte:))
macro:(nword:,100)
This set of definitions will cause incorrect Fortran code to be generated
because RFPP will attempt to expand the definition of
length:
before the definition of nword:
is available.
The correct definition of length:
is
macro:(length:,[arith:(nword:,*,nbyte:)])
because the square brackets prevent macro expansion until the invocation of
length:.