{$MACRO ON}
|
otherwise macros will be regarded as a symbol.
Defining a macro in a program is done in the same way as defining a symbol; in a {$define} preprocessor statement1 :
{$define ident:=expr}
|
If the compiler encounters ident in the rest of the source file, 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 infinite 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 defined 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 predefines 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 {$MACRO ON} directive.