[fpc-pascal] Using constants in constant record definition

Dejan Boras de.jean.7777 at gmail.com
Thu Jun 13 09:34:23 CEST 2019


It's not a bug. There's no support in FPC/Pascal for using constants with a
defined type in other declarations.
Define your MYINTEGERCONST without a type, and it should work.

const
  MYINTEGERCONST = 5;

On Wed, Jun 12, 2019 at 10:30 PM Simon Ameis <SAmeis.fpc at web.de> wrote:

> Hello,
>
> I'm just porting some C code to pascal. This code contains constant
> structure definitions which use other constants of simple types.
>
> However FPC reports "Error: Illegal expression" when using a constant
> within an constant record definition.
>
> program Project1;
>
> type
>   TMyRecord = record
>     x: Integer;
>   end;
>
> const
>   MYRECORDCONST2: TMyRecord = (x: 5); //< compiles fine
>   MYINTEGERCONST: Integer = 5;        //< defining integer const
>   MYRECORDCONST1: TMyRecord = (x: MYINTEGERCONST); //< using constant is
> no possible
> begin
> end.
>
> Is this intended or should I fill in a bug report? If it's intendet, I'm
> wondering why?
>
> Regards
> Simon Ameis
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20190613/d425d401/attachment.html>


More information about the fpc-pascal mailing list