Skip to content

delphi mode: pointer add operator symetry

Delphi supports simetry on pointer + operator. It can both: y := ptr + c; y = c + ptr;

But FPC fails on second.

On delphi 7 code below compile well:

unit test_ptr_distrib;
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}

interface
uses sysutils;

function ptr_twist() : boolean;

implementation

function ptr_twist() : boolean;
var
  x : pchar;
  x2 : pchar;
const
  str : ShortString = '123456789';
begin

  x := @(str[2]);
  x := x + 5;
  x2:= 5 + x;             // FPC fails here

  result := (x = x2);

end;

end.

imho, pointer sum simmetry gives less troubles on delphi code import

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information