FutureBasic Logo

<<    Index    >> FutureBasic

#define   statement



Syntax
[1] #define NewTypeName as OldTypeName
[2] #define NewTypeName as {pointer to|@|^|.} OldTypeName
[3] #define NewTypeName as {Handle to|@@|^^|..} OldTypeName
[4] #define MacroName value

Description
The #define statement is one way to create a name for a variable type (the other way to do so is to use the begin record statement). NewTypeName can be any new name you like that is different from the names of all existing types. OldTypeName is the name of an existing type; this can either be a built-in type such as Rect or int, or a type which you created previously, in a begin record statement or in another #define statement. After the #define statement, you can declare variables of the new type using dim statements, and you can pass NewTypeName to the sizeof and typeof functions.
If you use the first syntax, NewTypeName essentially becomes a synonym for OldTypeName. If you use syntaxes [2] or [3], then variables of the new type are recognized as pointers or handles to structures of OldTypeName. This is the only way to create a type name for pointers or handles to other types.

Syntax [4] creates a macro. A macro is similar to a constant in that wherever the name is used, it is replaced by the contents of the macro.
Examples:
#define BUFFER_SIZE 1024
#define NAME_KEY @"Name"
#define FRUIT @[@"Apple",@"Oranges",@"Lemons",@"Strawberries"]

Note
#define is non-executable, so you can't change its effect by putting it inside a conditional execution structure such as if...end if.
A non-executable statement inside a #if block will only be compiled if the condition following the #if is met. Otherwise it will be ignored.

See also
begin record; sizeof; typeof; dim