Sign in Join
Wiki copytemporary

Absolute: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Absolute

OldNewLine
1+The `absolute` [[modifier]] causes a [[Variable|variable]] to be stored at the same memory location as another variable.
2+
3+``` pascal
4+// Example on little endian x64 processor
5+Uses SysUtils;
6+
7+Var
8+ anInt : Integer;
9+ anotherInt : Integer absolute anInt;
10+ firstByte : Byte absolute anInt;
11+
12+begin
13+ // with both Integer variables at the same memory location, a change to one is reflected
14+ // in the other
15+ anInt := 20;
16+
17+ WriteLn(IntToStr(anInt) + ' ' + IntToStr(anotherInt)); // Outputs: 20 20
18+
19+ // a value of 20 fits in the first byte:
20+
21+ WriteLn('firstByte: ' + IntToStr(firstByte)); // Outputs: firstByte: 20
22+
23+ anotherInt := 333;
24+
25+ WriteLn(IntToStr(anInt) + ' ' + IntToStr(anotherInt)); // Outputs: 333 333
26+
27+ // 333 is too large a value to fit in one byte
28+ // little-endian x64 - least significant byte is first in memory:
29+ // 333 = 101001101 = 01001101 00000001 in memory = 0x4D 0x01 = decimal: 77 1
30+
31+ WriteLn('firstByte: ' + IntToStr(firstByte)); // Outputs: firstByte: 77
32+end.
33+```
34+
35+---
36+*From the Free Pascal wiki, page "Absolute", as it stood on 2022-08-06 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history