[fpc-devel] Minor doc error about "const param"

Michael Van Canneyt michael at freepascal.org
Mon Dec 20 20:31:59 CET 2021

On Mon, 20 Dec 2021, Martin Frb via fpc-devel wrote:

> On 20/12/2021 12:29, Michael Van Canneyt wrote:
>> On Mon, 20 Dec 2021, Martin Frb via fpc-devel wrote:
>>> Actually an commission, but an important one.
> https://www.freepascal.org/docs-html/current/ref/refsu67.html#x183-20700014.4.4 
>>> > Specifying a parameter as Constant is giving the compiler a hint 
>>> that the contents of the parameter will not be changed by the called 
>>> routine.
>>> "by the called routine."
>>> Should that not be "by any code (the caller, the called, or any 
>>> nested callee, or any other thread, interrupt or hardware modifying 
>>> memory)"?
>> If the value is copied then nothing else can change it since it is only
>> accessible to the routine itself ? (unless you're doing some really dirty
>> tricks, obviously)
> In the below example "GlobalTxt := 'abc';" is indeed in the "called 
> routine".
> But insert a call to a subroutine doing the work, or start a thread....
> procedure foo(const t: AnsiString);
> begin
>   GlobalTxt := 'abc';
>   // do some mem alloc/dealloc work
>   // do something with t, it still points to the location that the old 
> content was in. If that mem has been changed....

Well, that's what I meant with really dirty tricks.

I will probably have to rephrase the documentation to 
'The compiler will not allow you to modify the parameter value by assigning something directly to it."


More information about the fpc-devel mailing list