Enumerated types_(re)

Mon, 9 Jun 1997 13:02:39 +0100 (BST)


> > Is it possible to specify the value of an enumerated type? I was trying
> to
> > port a C header file which did something like this:
> > 
> >     typedef enum hello_everybody {
> >         hello_error = -1,
> >         hello_first =  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 write:

type  Hello_Everybody = (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.

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

type Hello_Everybody = 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.

Hope that helps


Dr E. Buxbaum (eb15@leicester.ac.uk)

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