Defining a manifest constantΒΆ
!define |
Define a manifest constant |
!undef |
Remove a symbol definition |
SYNTAX
!define symbol [text]
!undef symbol
The !define command causes all subsequent occurrences of symbol in the source code of a program to be replaced by text.
The !undef command removes the definition from symbol. The symbol is no longer recognised as defined by !if[n]def constructs.
symbol |
The symbol must be a single word. It may contain upper case or lower case letters, the digits 0-9 and the underscore character, but may not begin with a digit. It cannot be a Sculptor reserved word. From the point of the definition onwards, wherever symbol appears, unless it is within quotes, it is replaced by text. The replacement consists of all the text that follows the symbol, except for leading spaces, up to but not including the end of line. If symbol is already defined, the new definition replaces the original one from this point in the source code. Constants such as symbol are referred to as manifest constants. |
[text] |
The text to replace symbol may contain any alphanumeric characters. It is used exactly as typed, except that leading spaces are not included. It should not be enclosed in quotes unless these are required as part of the replacement string. All the text on the same physical line as the !define statement is included, up to but not including the end of line. The line continuation character (\) cannot be used to extend a line. The text may contain one or more other manifest constants, provided that their definitions have been declared with !define before this point in the source code. If text is omitted, symbol is defined but has a null value. This is useful for the purposes of the !if[n]def commands, which require only to know whether or not a symbol has been defined, regardless of its value. In the following example, the manifest constant TEST is defined but is assigned no value. The first block of statements will be compiled; the second block will not: !define TEST
!ifdef TEST
statements
!else
statements
!endif
|
NOTES
symbol will be replaced if it occurs inside curly braces (but not if it occurs inside quotes).
It is sensible to adopt a naming convention for manifest constants, so that they stand out clearly in the source code. One possibility is to use capital letters.
Certain manifest constants are already pre-defined in Sculptor. These are mostly located in standard include files in the directory $SCULPTOR/include. See Standard include files.
A symbol may also be defined by using the -D option when a program is compiled with the source code compiler scc.
An attempt to use !undef on a symbol which has not been defined causes a compiler error.
Pre-defined manifest constants such as ON and OFF may be undefined or redefined if required.
EXAMPLE
!define ALPHABET "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
!define PI 3.14
RELATED TOPICS |