Enumerated types_(re)

Mon, 09 Jun 1997 18:33:13 +0200


Hi!

Dr E. Buxbaum wrote:
> =

> > > Is it possible to specify the value of an enumerated type? I was tr=
ying
> > > to port a C header file which did something like this:
> > >
> > >     typedef enum hello_everybody {
> > >         hello_error =3D -1,
> > >         hello_first =3D  0,
> > >         hello_second,
> > >         hello_third
>  > Can this be done with GPC?
> =

> I am noot quite sure what you whant to do here. Under Pascal you can wr=
ite:
> =

> type  Hello_Everybody =3D (Hello_error, Hello_first, Hello_second,
>                                            Hello_third);
> =

> and then use the ORD function to get their numerical value.
> ORD(Hello_Error) would be 0, ORD(Hello_First) 1 and so on. This would
> be an enumerated type.
> =


I think that the use in the C-code fragment is ment to be something =

like this litle piece of Ada-code:

type hello_everybody is (hello_error, hello_first, hello_second,
hello_third);

-- this simply creates the enumerated type,

for hello_everybody use =

	(hello_error  =3D> -1, =

	 hello_first  =3D> 0, =

	 hello_second =3D> 4,  =

 	 hello_third  =3D> 17);

-- this tells the compiler what numeric values that are going to be used
-- for the enumerated symbols of that type.

(* in pascal this would mean*)

var x : hello_everybody;

begin
  x :=3D hello_third;
  writeln(' Ord(x)=3D', ord(x), ' equals 17');
end.



AFIK there is no way of specifying this in standard pascal. I GPC it =

would be nice if it was implemented, perhaps something similar to that
piece of Ada above.  =


Note that ord(pred(hello_second)) is 0.


> The other option would be a record (similar to a C struct):
> =

> type Hello_Everybody =3D record
>  			   Hello_Error,
>                          Hello_First,
>                          Hello_Second,
>                          Hello_Third     :  integer;
>                        end;
> =

> In this case you could assign any integer value you like to any of
> the records field, while in the case of enumeration types the
> ORD-value is given by the order of definition.

I don't think this was the intended function.

/Jakob :)

mailto:Jakob.Heinemann@ericsson.com
Ericsson Saab Avionics AB Link=F6ping
+46 13 284249


Jakob Heinemann (Jakob.Heinemann@ericsson.com)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es