Positron Compiler Documentation

Using the Preprocessor

Source: Positron8 Compiler User Manual, PDF page 474
Using the Preprocessor chapter divider

Using

the

Preprocessor

A pre-processor directive is a non executable statement that informs the compiler how to compile. For example, some microcontroller have certain hardware features that others don’t. A pre-processor directive can be used to inform the compiler to add or remove source code, based on that particular devices ability to support that hardware.

It’s important to note that the pre-processor works with directives on a line by line basis. It is therefore important to ensure that each directive is on a line of its own. Don’t place directives and source code on the same line.

It’s also important not to mistake the compiler’s pre-processor with the assembler’s preprocessor. Any directive that starts with a dollar “$” is the compiler’s pre-processor, and any directive that starts with a hash “#” is the assembler’s pre-processor. They cannot be mixed, as each has no knowledge of the other.

Pre-processor directives can be nested in the same way as source code statements. For example:

$ifdef MyValue
   $if MyValue = 10
      Symbol CodeConst = 10
   $else
      Symbol CodeConst = 0
   $endif
$endif

Pre-processor directives are lines included in the code of the program that are not BASIC language statements but directives for the pre-processor itself. The pre-processor is actually a separate entity to the compiler, and, as the name suggests, pre-processes the BASIC code before the actual compiler sees it. Pre-processor directives are always preceded by a dollar sign “$”.

Subtopics