Understanding the preprocessor
This is an introduction to the code preprocessor.
The preprocessor is used to transform your sources before compilation. It allows you to include other files and to define macros that will be expanded when used in the source. It behaves similar to the C preprocessor, with some differences.
It is recommended to avoid using the preprocessor
if there is an alternative in the native language. For example, instead
of defining program constants with an &define
macro,
use the CONSTANT
instruction. Other language features such as IMPORT FGL
increase code readability and modular
programming, without the need of a preprocessor.
The preprocessor transforms files as follows:
- The source file is read and split into lines.
- Continued lines are merged into one long line if it is part of a preprocessor definition.
- Comments are not removed unless they appear in a macro definition.
- Each line is split into a list of lexical tokens.
The preprocessor options can be passed as compilers command options.
- File inclusion
- Conditional compilation
- Macro definition and expansion. There are different kind of macros:
- Macros can be defined with operators for:
- You can undefine macros.
If a preprocessing directive is invalid, the compilers will generate an .err
file with the preprocessing error included in the source file at the line position where the problem
exists. When using the -M
option, preprocessor errors will be printed to stderr,
like regular compiler errors.