Difference between revisions of "Absolute/fr"

From Lazarus wiki
Jump to navigationJump to search
m (Fixed syntax highlighting; fixed wiki markup)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
{{Absolute}}
 
{{Absolute}}
  
Ce modificateur de déclaration indique la variable déclarée a la même adresse que la variable qui suit ''absolute''.
+
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.
 
Toutefois, aucune cohérence entre les valeurs des deux variables n'est assurée.
  
Line 20: Line 20:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
<syntaxhighlight lang="pascal">
 +
// Example on little endian 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:
  
[[Category:Reserved words/fr]]
+
    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
 +
    // little-endian x64 - least significant byte is first in memory:
 +
    // 333 = 101001101 =  01001101 00000001 in memory = 0x4D 0x01 = decimal: 77 1
 +
 
 +
    WriteLn('firstByte: ' + IntToStr(firstByte));          // Outputs: firstByte: 77
 +
end.
 +
</syntaxhighlight>

Latest revision as of 14:57, 19 December 2020

Deutsch (de) English (en) español (es) suomi (fi) français (fr) русский (ru)

Ce modificateur de déclaration indique la 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.

Var
  sintI: ShortInt;
  lintI: LongInt absolute sintI;

begin
  // Affichage correct
  lintI := 20;
  ShowMessage(inttostr(lintI) + '  ' + inttostr(sintI)); // Anzeige: 20  20

  // Affichage absurde
  lintI := 2000;
  ShowMessage(inttostr(lintI) + '  ' + inttostr(sintI)); // Anzeige: 2000 -45
end;
// Example on little endian 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
    // little-endian x64 - least significant byte is first in memory:
    // 333 = 101001101 =  01001101 00000001 in memory = 0x4D 0x01 = decimal: 77 1

    WriteLn('firstByte: ' + IntToStr(firstByte));           // Outputs: firstByte: 77
end.