{$MACRO ON}
|
otherwise macros will be regarded as a symbol.
De ning a macro in a program is done in the same way as de ning a symbol; in a f$defineg preprocessor statement1 :
{$define ident:=expr}
|
If the compiler encounters ident in the rest of the source le, it will be replaced immediately by expr. This replacement works recursive, meaning that when the compiler expanded one macro, it will look at the resulting expression again to see if another replacement can be made. This means that care should be taken when using macros, because an in nite loop can occur in this manner.
Here are two examples which illustrate the use of macros:
{$define sum:=a:=a+b;}
... sum { will be expanded to 'a:=a+b;' remark the absence of the semicolon} ... {$define b:=100} sum { Will be expanded recursively to a:=a+100; } ... |
The previous example could go wrong:
{$define sum:=a:=a+b;}
... sum { will be expanded to 'a:=a+b;' remark the absence of the semicolon} ... {$define b=sum} { DON'T do this !!!} sum { Will be infinitely recursively expanded \dots } ... |
On my system, the last example results in a heap error, causing the compiler to exit with a run-time error 203.
Remark:Macros de ned in the interface part of a unit are not available outside that unit! They can just be used as a notational convenience, or in conditional compiles.
By default the compiler prede nes three macros, containing the version number, the release number and the patch number. They are listed in table (2.1).
|
Remark:Don't forget that macro support isn't on by default. It must be turned on with the -Sm command-line switch or using the f$MACRO ONg directive.