[fpc-devel] Looking for clarification on what I think are obviously missing "const" prefixes for parameters in the methods of TRect (the typshrdh.inc one)

Jonas Maebe jonas at freepascal.org
Sun Jan 27 14:21:50 CET 2019


On 27/01/19 14:11, Walter Prins wrote:
> Would it perhaps be possible to treat this as a type of optimization 
> however?  Which is to say, if the called routine makes no changes to the 
> passed record, then it should not matter whether compiler implicitly 
> const passes the parameter or copies it?

It does, because another routine called by this routine may modify the 
original record.

E.g.

var
   r: record a: longint end;;

procedure modify;
begin
   r.a:=2;
end;

procedure test(r: trecord);
begin
   modify;
   if r.a<>1 then
     writeln('error');
end;

begin
   r.a:=1;
   test(r);
end.


Jonas



More information about the fpc-devel mailing list