[fpc-pascal] function const default argument
Michael Van Canneyt
michael at freepascal.org
Thu Aug 26 10:53:13 CEST 2021
On Thu, 26 Aug 2021, Santi via fpc-pascal wrote:
> El 26/08/2021 a las 10:00, Ondrej Pokorny via fpc-pascal escribió:
>> On 26.08.2021 09:40, Santiago A. via fpc-pascal wrote:
>>> const
>>> DefaultDelta:extended = 1E-8;
>>> function F(const x:extended; const delta:extended=DefaultDelta):extended;
>>> function G(const x:extended; const delta:extended=DefaultDelta):extended;
>>>
>>> But I get "Illegal expression" in the header function declaration.
>>> Const parameters don't accept const expressions?
>>
>> You need:
>>
>> const
>> DefaultDelta = 1E-8;
>>
>
> Thanks, it works fine.
>
> But I can't see why specifying the type doesn't work;
Because a typed constant behaves more like a variable then like a constant.
A leftover from Turbo Pascal, which used this construct for initialized
variables.
const
DefaultDelta = Extended(1E-8);
is a real typed constant.
Michael.
More information about the fpc-pascal
mailing list