Positron Compiler Documentation

Using the Preprocessor

Positron16 · Revision 1.1.3.5 · PDF pages 462–463

Using the Preprocessor

Original diagram or table from Positron16, PDF page 462
Original figure / layout · PDF page 462
Text in this figure or table

Using the Preprocessor

View original PDF page 462Open page in PDFOriginal PDF page 462

A preprocessor 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 preprocessor 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 preprocessor with the assembler’s preprocessor. Any directive that starts with a dollar “$” is the compiler’s preprocessor, and any directive that starts with a hash “#” is the assembler’s preprocessor. They cannot be mixed, as each has no knowledge of the other.

Preprocessor 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

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

View original PDF page 463Open page in PDFOriginal PDF page 463

Topics