The variables must be declared in a variable declaration block of a unit or a procedure or function
(section 16.5, page 967). It looks as follows:
_________________________________________________________________________________________________________
Variable declaration


___________________________________________________________________
This means that the following are valid variable declarations:
Var
curterm1 : integer;
curterm2 : integer; cvar;
curterm3 : integer; cvar; external;
curterm4 : integer; external name curterm3;
curterm5 : integer; external libc name curterm9;
curterm6 : integer absolute curterm1;
curterm7 : integer; cvar; export;
curterm8 : integer; cvar; public;
curterm9 : integer; export name me;
curterm10 : integer; public name ma;
curterm11 : integer = 1 ;
curterm12 : integer absolute $00123456;
curterm13 : integer absolute @curterm12+8;
curterm14 : integer absolute a;
The difference between these declarations is as follows:
- The first form (curterm1) defines a regular variable. The compiler manages everything
by itself.
- The second form (curterm2) declares also a regular variable, but specifies that the
assembler name for this variable equals the name of the variable as written in the
source, using C mangling of the assembler name (meaning it gets prefixed with a _
character on some platforms).
- The third form (curterm3) declares a variable which is located externally: the
compiler will assume memory is located elsewhere, and that the assembler name of this
location is specified by the name of the variable, as written in the source. The name
may not be specified.
- The fourth form is completely equivalent to the third, it declares a variable which is
stored externally, and explicitly gives the assembler name of the location. If cvar is
not used, the name must be specified.
- The fifth form is a variant of the fourth form, only the name of the library in which
the memory is reserved is specified as well.
- The sixth form declares a variable (curterm6), and tells the compiler that it is stored
in the same location as another variable (curterm1).
- The seventh form declares a variable (curterm7), and tells the compiler that the
assembler label of this variable should be determined as the C compiler for the current
platform would determine it, additionally it must be made public. i. e. it can be
referenced from other object files.
- The eighth form (curterm8) is equivalent to the seventh: “public” is an alias for
“export”.
- The ninth and tenth form are equivalent: they specify the assembler name of the
variable.
- the eleventh form declares a variable (curterm11) and initializes it with a value (1 in
the above case).
- The twelfth form declares a variable (curterm6a), and tells the compiler that it is stored
at the absolute address $00123456 (hexadecimal).
- The thirteenth form uses an integer expression that resolves to a constant value. Note
that you can take an address of a previously defined variable as base offset.
- the fourteenth form shows you can use an assembler name (label) as address.
Note that assembler names must be unique. It’s not possible to declare or export two variables
with the same assembler name. In particular, do not attempt to export variables with a public
name that starts with FPC_; the compiler uses some internal system routines with this
name.
As for any identifier, variables can be accompagnied by hint directives (section 1.5, page
53):
var
curold : integer deprecated;