[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}
{$endif}
{$apptype console}
function Func(const S : string):string;
begin
 Result := S;
 pchar(Result)^ := succ(pchar(result)^);
end;

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

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