[fpc-devel] Passing consts to const
David Butler
david at e.co.za
Tue Jun 7 20:47:51 CEST 2005
On Tue, 07 Jun 2005 19:59:56 +0200, you wrote:
>David Butler wrote:
>> {$WRITEABLECONST OFF}
>>
>> procedure TestBuf(const Buf; Size: Integer);
>> begin
>> end;
>>
>> const A : Byte = 1;
>
> From this point A is treated as a normal variable with an initial
>assignment...
>
>>
>> begin
>> TestBuf(A, 1);
>
>... so it is not const here.
It is perfectly legal to pass a "var" to a "const". The problem is
that FPC thinks we are trying to change A.
>
>Guess if you would substitute the line
> > const A : Byte = 1;
>with
> > const A = 1;
>
>It should work. AFAIR, typed constants are treated exactly as variables
>with an initial value.
Exactly. If it is treated like a normal variable, why the error
message?
The problem is not with the "const A" declaration, the problem is with
the the call to TestBuf not allowing a "constant variable" to be
passed (like Delphi rightly does).
Although the TestBuf call compiles with your suggested "const A = 1"
declaration in FPC, it doesn't make sense (and it rightly doesn't
compile in Delphi).
I don't want to say FPC should be doing everything the way Delphi
does, but in this case it makes sense, in my opinion.
Regards
David
More information about the fpc-devel
mailing list