[fpc-devel] "case" with range stupidities

Daniël Mantione daniel.mantione at freepascal.org
Thu Feb 15 14:06:05 CET 2007



Op Thu, 15 Feb 2007, schreef Vinzent Hoefler:

> program
>    Case_Test;
> =

> type
>    My_Range =3D 2000 .. 3000;
> =

> var
>    X : Integer;
> =

> begin
>    X :=3D 2500;
> =

>    case X of
>       Low (My_Range) .. High (My_Range) : WriteLn ('In range. (1)');
>       My_Range                          : WriteLn ('In range. (2)');
>    else
>       WriteLn ('Out of range.');
>    end {case};
> end {Case_Test}.
> =

> -- 8< --
> =

> Is there any reasoning why the first switch in the case statement ("Low =

> (My_Range) ...") is allowed, whilst the second one (just "My_Range") is =

> not (says: "constant expression expected")?

Well, a case label is basically a set of values. A type definition is somet=
hing =

different, i.e. you cannot use "byte" or "longint" as case labels either. =

Afaik set names aren't allowed either but allowing these would seem more =

logical to me than allowing type names (seeing byte and longint as case =

labels would seem weird to me.


> Another minor issue is that a type declaration like:
> =

>    type
>       My_Range =3D (2500 - 500) .. (2500 + 500);
> =

> is not accepted (message similar to ";" expected, ".." found) and =

> (basically the same declaration)
> =

>    type
>       My_Range =3D 2500 - 500 .. 2500 + 500;
> =

> is. Sometimes I'd really like to add those parantheses just to make the =

> intention more clear.

I think this is a parser limitation. I don't think it is a problem to =

allow it.

Dani=EBl


More information about the fpc-devel mailing list