Closed 3FLLC closed 6 years ago
This code snippet two ANSI Strings are acting like they are pointers to the same memory address...
{$R-} procedure TestChar(var c: Char); begin c := 'u'; end;
procedure TestStr(s: String); begin s[2] := 'u'; end;
var s1, s2: AnsiString; begin s1 := 'wat'; s2 := s1; TestStr(s1); Assert(s1[2] = 'a'); Assert(s2[2] = 'a');
s1 := 'wat'; s2 := s1; s1[2] := 'u'; Assert(s1[2] = 'u'); Assert(s2[2] = 'a');
s1 := 'wat'; s2 := s1; Writeln(s1); Writeln(s2); TestChar(s1[2]); Writeln(s1); Writeln(s2); Assert(s1[2] = 'u'); Assert(s2[2] = 'u'); Writelns1); Writeln(s2); end.
The Writeln's say: wat wat wut wut wut wut
FPC does not produce this same output.
It's a known issue, see issue #85.
This code snippet two ANSI Strings are acting like they are pointers to the same memory address...
{$R-} procedure TestChar(var c: Char); begin c := 'u'; end;
procedure TestStr(s: String); begin s[2] := 'u'; end;
var s1, s2: AnsiString; begin s1 := 'wat'; s2 := s1; TestStr(s1); Assert(s1[2] = 'a'); Assert(s2[2] = 'a');
s1 := 'wat'; s2 := s1; s1[2] := 'u'; Assert(s1[2] = 'u'); Assert(s2[2] = 'a');
s1 := 'wat'; s2 := s1; Writeln(s1); Writeln(s2); TestChar(s1[2]); Writeln(s1); Writeln(s2); Assert(s1[2] = 'u'); Assert(s2[2] = 'u'); Writelns1); Writeln(s2); end.
The Writeln's say: wat wat wut wut wut wut
FPC does not produce this same output.