Sign in Join
Wiki copytemporary

Absolute/fr: what changed

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

Title: Absolute/fr

OldNewLine
1+Ce [[modifier/fr|modificateur]] de déclaration indique la [[Variable/fr|variable]] déclarée est à la même adresse que la variable qui suit *absolute*. Toutefois, aucune cohérence entre les valeurs des deux variables n'est assurée.
2+
3+``` pascal
4+Var
5+ sintI: ShortInt;
6+ lintI: LongInt absolute sintI;
7+
8+begin
9+ // Affichage correct
10+ lintI := 20;
11+ ShowMessage(inttostr(lintI) + ' ' + inttostr(sintI)); // Anzeige: 20 20
12+
13+ // Affichage absurde
14+ lintI := 2000;
15+ ShowMessage(inttostr(lintI) + ' ' + inttostr(sintI)); // Anzeige: 2000 -45
16+end;
17+```
18+
19+``` pascal
20+// Example on little endian x64 processor
21+Uses SysUtils;
22+
23+Var
24+ anInt : Integer;
25+ anotherInt : Integer absolute anInt;
26+ firstByte : Byte absolute anInt;
27+
28+begin
29+ // with both Integer variables at the same memory location, a change to one is reflected
30+ // in the other
31+ anInt := 20;
32+
33+ WriteLn(IntToStr(anInt) + ' ' + IntToStr(anotherInt)); // Outputs: 20 20
34+
35+ // a value of 20 fits in the first byte:
36+
37+ WriteLn('firstByte: ' + IntToStr(firstByte)); // Outputs: firstByte: 20
38+
39+ anotherInt := 333;
40+
41+ WriteLn(IntToStr(anInt) + ' ' + IntToStr(anotherInt)); // Outputs: 333 333
42+
43+ // 333 is too large a value to fit in one byte
44+ // little-endian x64 - least significant byte is first in memory:
45+ // 333 = 101001101 = 01001101 00000001 in memory = 0x4D 0x01 = decimal: 77 1
46+
47+ WriteLn('firstByte: ' + IntToStr(firstByte)); // Outputs: firstByte: 77
48+end.
49+```
50+
51+---
52+*From the Free Pascal wiki, page "Absolute/fr", as it stood on 2020-12-19 after a change by E-ric, 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