Question about use of enum in typedef and struct
Steve Cavrak
cavrak at uvm-gen.UUCP
Sat Apr 30 01:47:49 AEST 1988
Can someone explain why the following uses (abuses?) of typdef and enum
create problems in the struct that follows them? (The example is taked
from a once working program that was being ported to a new compiler that
is "now ANSI" compliant. The code has been "tested" on VAX BSD 4.3, VAX
VMS, and Turbo-C. The "new" compiler is Waterloo C 3.0.) The available
C documentation is not enlightening. I'm sure that my Pascal mindset
adds to the confusion.
/* Imnotok.c */
/* Confusion using enumerated types in structures */
/* */
/* The "_ok" declaration is usable in the struct definition AND */
/* the "_to" declaration is usable, BUT */
/* the "_no" declaration generates a syntax error. */
/* */
/* Why? */
/* ------------------------------------------------------------------ */
typedef int s_state_ok; /* OK */
typedef enum s_state_ok {
initial_ok, middle_ok, final_ok
};
typedef int s_state_to; /* OK */
enum s_state_to {
initial_to, middle_to, final_to
};
typedef enum s_state_no { /* NOT OK */
initial_no, middle_no, final_no
};
struct {
int m;
int n;
s_state_ok s; /* s_state_ok works, s_state_no fails */
} machine_state;
main ()
{
}
----------------------------------------------------------------
_______
|| | Stephen J. Cavrak, Jr. BITNET: sjc at uvmvm
|* | CSNET : cavrak at uvm
| / Academic Computing Services USENET: cavrak at uvm-gen
| | University of Vermont
| | Burlington, Vermont 05405
----
More information about the Comp.lang.c
mailing list