[comp.lang.c] Is this legal ANSI?

kdq@demott.com (Kevin D. Quitt) (01/15/91)

    Microsoft C 6.0 accepts:

struct	master_log_entry
   {
    struct  log_entry	le;
    union
       {
        struct	gas_log_entry       gle;
        struct  status_log_entry    sle;
        struct  valve_log_entry     vle;
        struct  heat_log_entry      hle;
        struct  tool_log_entry      tle;
        struct  alarm_log_entry     ale;
       };
   };

struct master_log_entry	mle;


    then accepts references like:

	mle.gle.<reference to inside of gas_log_entry struct>

    and:

	&mle.gle


    without a complaint.  Am I just lucky?  gcc takes the definitions
(-ansi) but will not compile the code (i.e. `structure has no member named
"gle"').

    I really like being able to do that.  Anybody got the "Truth"?

-- 
 _
Kevin D. Quitt         demott!kdq   kdq@demott.com
DeMott Electronics Co. 14707 Keswick St.   Van Nuys, CA 91405-1266
VOICE (818) 988-4975   FAX (818) 997-1190  MODEM (818) 997-4496 PEP last

henry@zoo.toronto.edu (Henry Spencer) (01/16/91)

In article <1991Jan14.225620.9974@demott.com> kdq@demott.com (Kevin D. Quitt) writes:
>    Microsoft C 6.0 accepts:
>struct	master_log_entry
>   {
>    struct  log_entry	le;
>    union
>       {
>        struct	gas_log_entry       gle;
>		...
>       };
>   };
>
>	mle.gle.<reference to inside of gas_log_entry struct>
>	...
>
>    without a complaint.  Am I just lucky?

Yes.  Nameless members are illegal in ANSI C (except for the special case
of nameless bitfields).  Some compilers support this as an extension.
-- 
If the Space Shuttle was the answer,   | Henry Spencer at U of Toronto Zoology
what was the question?                 |  henry@zoo.toronto.edu   utzoo!henry