Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2004-04

string constant violation

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ozerski Pavel

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).

Reply by email

Jonas Maebe
to Ozerski Pavel
Ozerski Pavel wrote
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).

The Delphi 3 behaviour is the correct one imho, and should also become the FPC behaviour once we start storing constant data in a read-only section.

Jonas

Reply by email