4.2 Declaration

The variables must be declared in a variable declaration section of a unit or a procedure or function. It looks as follows:

_________________________________________________________________________________________________________ Variable declaration
-- --variable declaration-identi  er :- type--|---------------
                                      -= - expression --
- ---|----------------;--------------------------------------------
     -variable modi ers--

-- variable modi ers --------------absolute--|integer expression---------------
                  6 ||                  -----identi  er -----           ||
                  | |-------------------; export--------------------||
                  | |--------------------; cvar---------------------||
                  | -; external---------------------------------------|
                  --------------string constant---name---string-constant----|
- -----------------------------------------------------------------
___________________________________________________________________

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 dierence between these declarations is as follows:

  1. The rst form (curterm1) denes a regular variable. The compiler manages everything by itself.
  2. The second form (curterm2) declares also a regular variable, but species 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 specied by the name of the variable, as written in the source. The name may not be specied.
  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 specied.
  5. The fth form is a variant of the fourth form, only the name of the library in which the memory is reserved is specied 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 les)
  8. The eight 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 elevents 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 2 variables with the same assembler name.