#define
Defines identifier to be replaced by specified replacement string.
Syntax
#define identifier [(parameter [, parameter ])] string
Parameters
- Identifier
- Keyword defined by user which is an abbreviation for the string parameter. Rules for identifiers are as follows:
The first character must be alphabetic while the characters which follow may be alphanumeric or an underscore ( _ ).
Spaces or tab characters are not allowed as part of the identifier.
- Parameters
- Normally used to specify a variable or multiple variables which may be used by the replacement string. This provides a dynamic define mechanism which can be used like a macro. #A maximum of up to 8 parameters may be used with the #define command. However, each parameter must be separated by a comma and the parameter list must be enclosed within parenthesis.
- string
- This is the replacement string which replaces the identifier when the program is compiled. Rules regarding replacement strings are as follows:
Spaces or tabs are allowed in replacement strings.
Identifiers used with other #define statements cannot be used as replacement strings.
If the comment symbol ( ' ) is included, the characters following the comment symbol will be treated as a comment and will not be included in the replacement string.
The replacement string may be omitted. In this case the specified identifier is replaced by "nothing" or the null string. This actually deletes the identifier from the program
Description
The #define instruction causes a replacement to occur within a program for the specified identifier. Each time the specified identifier is found the identifier is replaced with the replacement string prior to compilation. However, the source code will remain with the identifier rather than the replacement string. This allows code to become easier to read in many cases by using meaningful identifier names rather than long difficult to read strings of code.
The defined identifier can be used for conditional compiling by combining with the #ifdef or #ifndef commands.
If a parameter is specified, the new identifier can be used like a macro.
Note
#Using #define for variable declaration or label substitutions will cause an error:
It should be noted that usage of the #define instruction for variable declaration will cause an error.
See Also
#ifdef, #ifndef
#define Example
' Uncomment next line for Debug mode.
' #define DEBUG
Input #1, A$
#ifdef DEBUG
Print "A$ = ", A$
#endif
Print "The End"
#define SHOWVAL(x) Print "var = ", x
Integer a
a = 25
SHOWVAL(a)