[fpc-pascal] const parameter writeable

Peter Vreman peter at freepascal.org
Sat Apr 29 23:20:04 CEST 2006


>
> Are const parameters supposed to ensure read only access?
> If so how come one can write to a typed pointer?
>
> program project1;
>
> {$mode objfpc}{$H+}
>
>   type
>     PSomeRec = ^TSomeRec;
>     TSomeRec = record
>       a: string;
>       b: string;
>     end;
>
>   procedure ChangeRec1(const Rec: PSomeRec);
>   begin
>     Rec^.a:= 'string A';
>   end;
>
> var
>   RecPtr: PSomeRec;
> begin
>   new(RecPtr);
>   ChangeRec1(RecPtr);
>   writeln(RecPtr^.a);
>   dispose(RecPtr);
>   readln;
> end.

Only the pointer itself is the parameter and read-only. Where the pointer
points to is irrelevant.








More information about the fpc-pascal mailing list