[fpc-pascal] Typed constant
Jonas Maebe
jonas.maebe at elis.ugent.be
Fri Oct 24 22:34:45 CEST 2008
On 24 Oct 2008, at 21:51, Valdas Jankūnas wrote:
> const
> MAX_LAIKO_JUOSTA: TLaikoJuosta=(Valanda: 99; Minute: 59);
>
> I want create another constant:
>
> MAX_LAIKO_JUOSTA_MINUTEMIS=MAX_LAIKO_JUOSTA.Valanda*MinsPerHour
> +MAX_LAIKO_JUOSTA.Minute;
>
> But compiler (I working in Lazarus v0.9.27 r16994 i386-linux-gtk 2
> (beta); fpc 2.2.2) reported "Error: Illegal expression" and cursor
> blinks at end of line of new constant. Same error if I try:
>
> MAX_LAIKO_JUOSTA_MINUTEMIS:
> SmallInt=MAX_LAIKO_JUOSTA.Valanda*MinsPerHour+MAX_LAIKO_JUOSTA.Minute;
>
> I creating constant from a constant. But why I getting that error?
Because a "typed constant" is a bad name chose by Borland for
"initialised variable". And you cannot use variables (initialised or
not) in constant expressions.
With {$j-} typed constants become real constants (they cannot be
changed anymore, unlike in the default {$j+} state), but even then the
above probably won't work because while parsing the compiler directly
writes the values of such constants/initialised variables in the
assembler list rather than constructing some semantic entity which can
be reused later (so the compiler has no way to retrieve the values of
such constants when you try to reuse them later on).
Jonas
More information about the fpc-pascal
mailing list