Pascal Wiki
Advertisement

Compiler directives are special intructions to the compiler that do not, themselves, generate code, but instead control the behaviour of the compiler. There are only three ways to issue compiler directives to the compiler to provide certain information to the compiler about the program being compiled. These are:

  • Put compiler switches into the command line used to invoke the compiler. If there are a large number of directives to pass to the compiler, this can become unwieldy.
  • Put a configuration file reference in the command line, then put the compiler directives into that file. This is the most common practice on larger applications.
  • Insert the compiler directive directly into the program by placing it inside a comment in the source code. All comments that begin with a "$" sign are interpreted as compiler directives. These can do a number of things, includint enable conditional compilation, disable various checks, or enable special warnings.

For example, the compiler directive "{$R+}" enables range checking, "{$R-}" disables it. Another common directive is {$I-} used before opening a file to prevent an error if not found.

Advertisement