Path: utzoo!mnetor!uunet!uvm-gen!cavrak From: cavrak@uvm-gen.UUCP (Steve Cavrak) Newsgroups: comp.lang.c Subject: Question about use of enum in typedef and struct Message-ID: <823@uvm-gen.UUCP> Date: 29 Apr 88 15:47:49 GMT Organization: EMBA Computer Facility, Univ. of Vermont, Burlington. Lines: 51 Keywords: enum, typedef, struct, syntax 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@uvmvm |* | CSNET : cavrak@uvm | / Academic Computing Services USENET: cavrak@uvm-gen | | University of Vermont | | Burlington, Vermont 05405 ----