Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2026-01

typed constants

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

P Padil

I attempted to use a typed constant:

const
	tprob : Double = 0.020;

But the compiler (3.2.2) balked as illegal expression. Am i misreading section "2.2 Typed constants” in the reference manual?

Thanks,
Pete

P Padil
to P Padil
Ok I should have read the error message, the problem is with the following declaration, not the first:
const
   tprob: double = 0.020000000;
   lprob: double = tprob/1e4;

If I remove the types then it compiles, with the types it says "Error: Illegal expression” on the second declaration.

Show quoted text 11 lines
On Jan 2, 2026, at 10:57 AM, P Padil wrote: I attempted to use a typed constant: const tprob : Double = 0.020; But the compiler (3.2.2) balked as illegal expression. Am i misreading section "2.2 Typed constants” in the reference manual? Thanks, Pete
Mattias Gaertner
to P Padil
P Padil wrote
Ok I should have read the error message, the problem is with the following declaration, not the first: const tprob: double = 0.020000000; lprob: double = tprob/1e4;

For legacy reasons these actually declare variables.

Maybe you want

const
     tprob = double(0.02);
     lprob = double(tprob/1e4);

Mattias

Show quoted text 18 lines
If I remove the types then it compiles, with the types it says "Error: Illegal expression” on the second declaration. > On Jan 2, 2026, at 10:57 AM, P Padil wrote: > > I attempted to use a typed constant: > > const > tprob : Double = 0.020; > > But the compiler (3.2.2) balked as illegal expression. Am i misreading section "2.2 Typed constants” in the reference manual? > > Thanks, > Pete _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
P Padil
to Mattias Gaertner

Ah ok, thanks.

Show quoted text 41 lines
On Jan 2, 2026, at 12:47 PM, Mattias Gaertner via fpc-pascal wrote: On 1/2/26 20:16, P Padil via fpc-pascal wrote: > Ok I should have read the error message, the problem is with the following declaration, not the first: > const > tprob: double = 0.020000000; > lprob: double = tprob/1e4; For legacy reasons these actually declare variables. Maybe you want const tprob = double(0.02); lprob = double(tprob/1e4); Mattias > If I remove the types then it compiles, with the types it says "Error: Illegal expression” on the second declaration. >> On Jan 2, 2026, at 10:57 AM, P Padil wrote: >> >> I attempted to use a typed constant: >> >> const >> tprob : Double = 0.020; >> >> But the compiler (3.2.2) balked as illegal expression. Am i misreading section "2.2 Typed constants” in the reference manual? >> >> Thanks, >> Pete > _______________________________________________ > fpc-pascal maillist - > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal