modula-2 home

  Win32 API  


Variable declarations

Variables are objects that have values that change during the execution of a program.  Variables are created by a variable declaration.  The format of the variable declaration is:

VAR {identifier {,identifier}: TypeSpecification;}

Each of the identifiers to the left of the colon is declared as a variable of the type that is specified to the right of the colon. TypeSpecification can be either a type name or a new type.

The following are examples of variable declarations:

 MAT : ARRAY [1..3],[1..3] OF REAL;
 BackGround, ForeGround : Color;
 PossibleColors : SET OF Color;
 RecordPointer : POINTER TO RecType;

Absolute variables

You can give the absolute address of a variable as follows:

VAR identifier [MAKEADR(constant)] : TypeSpecifiation;
VAR identifier [MAKEADR(constant, constant)] : TypeSpecifiation;

MAKEADR is imported from the ISO module SYSTEM. The two different forms of MAKEADR are due to the segmented nature of the 80x86 processor. If MAKEADR is passed a single constant the value represents the offset of the address relative to the data segment. When two constants are passed they are the segment and the offset, respectively, of the absolute address.

When you give an absolute address, the compiler does not allocate space for the variable, but refers to the address you specify.


VAR screen [MAKEADR(0B800H,0)] : ScreenType;

The variable screen refers to the screen memory of the color display adaptor in an IBM PC.


  • Stony Brook Modula-2 documentation. Used with permission. Note: Stony-Brook M2 offers an extended syntax with features not described here. Stony Brook M2 users are encouraged to visit the Stony Brook website and to consult the Stony Brook help system.