[fpc-devel]string constant violation

"?=Ozerski Pavel=?koi8-r?Q?" ozerski at list.ru
Fri Apr 16 09:06:33 CEST 2004

Hello all,
I got from a Russian FPC forum a sample that demonstrates a strang behavior. That is this sample:

{$ifdef fpc}
{$mode delphi}
{$apptype console}
function Func(const S : string):string;
 Result := S;
 pchar(Result)^ := succ(pchar(result)^);

var I : integer;
 for I:=1 to 3 do
   WriteLn(Func('12345 '));

This sample makes permanent changes in a string constant. If this sample will be compiled in Delphi it restores previous constant value (and all calls of the function Func return the same result; Delphi 6) or crashs with RTE 216 (Delphi 3).

More information about the fpc-devel mailing list