Absolute

This is an old revision of Absolute, edited by FPC user at . The current revision is 105655.

initial text

The absolute modifier causes a variable to be stored at the same memory location as another variable.

// Example on x64 processor
Uses SysUtils;

Var
    anInt      : Integer;
    anotherInt : Integer absolute anInt;
    firstByte  : Byte absolute anInt;
 
begin
    // with both Integer variables at the same memory location, a change to one is reflected
    // in the other
    anInt := 20;
    WriteLn(IntToStr(anInt) + '  ' + IntToStr(anotherInt)); // Outputs: 20  20

    // a value of 20 fits in the first byte:
    WriteLn('firstByte: ' + IntToStr(firstByte)); // Outputs: firstByte: 20
   
    anotherInt := 333;
    WriteLn(IntToStr(anInt) + '  ' + IntToStr(anotherInt)); // Outputs: 333 333

    // 333 is too large a value to fit in one byte
    // 333 = 101001101 = 00000001 01001101 = 1 77 
    WriteLn('firstByte: ' + IntToStr(firstByte)); // Outputs: firstByte: 77
end.