var variable_name: data_type absolute variable_reference;
or
var variable_name: data_type absolute integer_expression;
The first meaning of the absolute directive allows to put a variable to the address of another one and thus provides a type-casting mechanism.
In most cases, variable_reference will be just a variable name, but GPC also allows arbitrary pointer expressions here. If variable_reference has neither a constant address nor is a variable parameter, GPC prints a warning. This warning is suppressed in “extended syntax” mode which is switched on by the --extended-syntax option or the {$X+} compiler directive.
GPC also allows explicit type casts. Variant records (as defined in ISO 7185 Pascal), however, have no guaranteed overlaying and are therefore not suitable for type casts.
The second meaning of absolute places a variable at a specified address. This is useful on machines without virtual memory addressing for doing certain low-level operations, but should be avoided on systems with memory protection such as Unix-like systems. GPC does not check whether the specified virtual address makes any sense and does not provide a built-in mechanism to map it to a real address.
GPC warns about this second use of absolute unless “extended syntax” has been requested.
absolute is a Borland Pascal extension.
Borland Pascal has a slightly different syntax for the second meaning related to the addressing scheme of IA32 processors working in real mode.
Allowing arbitrary memory references instead of just variable names in the first meaning of absolute is a GNU Pascal extension.
program AbsoluteDemo; {$X+} const IOMem = $f0000000; MaxVarSize = MaxInt div 8; var Mem: array [0 .. MaxVarSize - 1] of Byte absolute 0; { This address has no actual meaning } MyPort: Byte absolute IOMem + $c030; { Beware: Using any of the variables above will crash your program unless you know exactly what you do! That's why GPC warns about it without the $X+ directive. } var x: Real; a: array [1 .. SizeOf (Real)] of Byte absolute x; i: Integer; b: Byte absolute a[i]; { GNU Pascal extension: non-constant memory reference. } begin x := 3.14; { Look at the internal representation of a real variable. } for i := 1 to SizeOf (Real) do Write (a[i] : 4); WriteLn; { The same again, more ugly ... } for i := 1 to SizeOf (Real) do Write (b : 4); WriteLn; { And yes, there's an even more ugly way to do it ... } for i := 1 to SizeOf (Real) do Write (Mem[PtrCard (@x) + i - 1] : 4); WriteLn end.