The compiler supports the definition of aliases. An alias is a unique identifier that can be used in programs to replace another text. Definitions are typically used for replacing a constant expression and ease the maintenance of programs.
There are three levels of definitions:
- common to all the projects installed on your machine
- global to all programs of a project
- local to one program
Common and global definitions can edited from the "File / Open" menu of the main window. Local definitions are edited together with the corresponding program. Use the "View / Local Defines" menu command when editing a program to open its local definitions.
Definitions are entered in a text editor. Each definition must be entered on one line of text according to the following syntax:
#define Identifier Equivalence (* comments *)
Below are some examples:
(* redefinition of FALSE constant
#define PI 3.14 (* numerical constant *)
#define ALARM (bLevel > 100) (* complex expression *)
You can use a definition within the contents of another definition. The definition used in the other one must be declared first. Below is an example:
A definition may be empty, for example:
Defined word can be used for directing the conditional compiling directives.
You can enter #define lines directly in the source code of programs in IL or ST languages.
The use of definitions may disturb the program monitoring and make error reports more complex. It is recommended to restrict the use of definitions to simple expressions that have no risk to lead to a misunderstanding when reading or debugging a program.
The following words are predefined by the compiler and can be used in the programs:
of compiling expressed as a string constant expression
Name of the machine where compiling is run, expressed as a string constant expression.
Name of the user where compiling is run, expressed as a string constant expression.
The following ST program sets variables declared as STRING(255):
strMachine := __MACHINE__;
strUser := __USER__;
strMachine is 'LabtopJX'
strUser is 'John'