[fpc-devel] "case" with range stupidities

Vinzent Hoefler JeLlyFish.software at gmx.net
Thu Feb 15 14:13:49 CET 2007


On Thursday 15 February 2007 13:06, Daniƫl Mantione wrote:
> Op Thu, 15 Feb 2007, schreef Vinzent Hoefler:
> > program
> >    Case_Test;
> >
> > type
> >    My_Range = 2000 .. 3000;
> >
> > var
> >    X : Integer;
> >
> > begin
> >    X := 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
> something different, i.e. you cannot use "byte" or "longint" as case
> labels either.

Well, fair enough, but why is that I can declare a

   type
      Foo = array[byte] of Something;

where the type name "byte" also indicates the range? Considering that

   type
      Foo = array[Low (byte) .. High (byte) of Something;

is totally equivalent, the allowed usage of range types seems a little 
bit inconsistent...


Vinzent.




More information about the fpc-devel mailing list