4.2 Declaration

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

_________________________________________________________________________________________________________
Variable declaration

 --variable declaration-identifier- :- type------------------
--------------------          -  ----=---expression------------------
   -             --|hint directive  ;
    variable modifiers

 variable modifiers--------------absolute--|integer expression---------------
                | -------------------------identifier-----------------||
                | --------------------; export--------------------||
                | -; external-----------; cvar---------------------||
                | |          -string constant-|-name - string constant--|||
                | -------------------hint directive-------------------||
                ---------------------------------------------------|
-----------------------------------------------------------------
___________________________________________________________________

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 ;

The difference between these declarations is as follows:

  1. The first form (curterm1) defines a regular variable. The compiler manages everything by itself.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. The sixth form declares a variable (curterm6), and tells the compiler that it is stored in the same location as another variable (curterm1).
  7. The seventh form declares a variable (curterm7), and tells the compiler that the assembler label of this variable should be the name of the variable (case sensitive) and must be made public. i. e. it can be referenced from other object files.
  8. The eighth form (curterm8) is equivalent to the seventh: “public” is an alias for “export”.
  9. The ninth and tenth form are equivalent: they specify the assembler name of the variable.
  10. the eleventh form declares a variable (curterm11) and initializes it with a value (1 in the above case).

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.