Sign in Join
Wiki copytemporary

Absolute/ru: what changed

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

Title: Absolute/ru

OldNewLine
1+Модификатор **absolute** предписывает хранить данную переменную в той же области памяти, в которой хранится и другая переменная.
2+
3+``` pascal
4+// Пример для процессоров x64 с порядком расположения байт от младшего к старшему (little endian)
5+Uses SysUtils;
6+
7+Var
8+ anInt : Integer;
9+ anotherInt : Integer absolute anInt;
10+ firstByte : Byte absolute anInt;
11+
12+begin
13+ // обе целочисленные переменные расположены в одной области памяти, при этом изменение одной из них приводит к изменению другой
14+ anInt := 20;
15+
16+ WriteLn(IntToStr(anInt) + ' ' + IntToStr(anotherInt)); // Выводится: 20 20
17+
18+ // значение 20 соответствует первому байту:
19+
20+ WriteLn('firstByte: ' + IntToStr(firstByte)); // Выводится: firstByte: 20
21+
22+ anotherInt := 333;
23+
24+ WriteLn(IntToStr(anInt) + ' ' + IntToStr(anotherInt)); // Выводится: 333 333
25+
26+ // 333 слишком большое значение, чтобы уместиться в одном байте
27+ // little-endian x64 - младший байт идет первым в памяти (по меньшему адресу):
28+ // 333 = 101001101 = 01001101 00000001 в памяти выглядит как = 0x4D 0x01 = десятичное значение: 77 1
29+
30+ WriteLn('firstByte: ' + IntToStr(firstByte)); // Выводится: firstByte: 77
31+end.
32+```
33+
34+---
35+*From the Free Pascal wiki, page "Absolute/ru", as it stood on 2020-01-25 after a change by Trev, 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