Illegal union question

Paul De Bra debra at alice.UUCP
Sun Feb 26 06:26:09 AEST 1989


In article <833 at wzlr.UUCP> jms at wzlr.UUCP (Jack Stephens) writes:
>
>The following declaration yeilds an "illegal member use" error
>for both f and next under the compilers on both by PC and my 3B1 
>and I can't seem to understand why.  Amybody feel pedegogical ?
>
>jms
>
>typedef struct m_i {
>  int type;
>	 union {
>	 int (*f)();
>	 struct m_i *next;
>	 }
>} menu[10];

Aha, different compilers have a different opinion on this one.
First of all, whether the definition is correct or not, the union needs
a name, thus
	union {
	...
	} name_of_union;

This is a nuisance because one must access fields like
mymenu[5].name_of_union.next instead of mymenu[5].next
However, one can have several unions inside the same struct, and such a
union may have fields with names that also appear in some other union.

Some compilers accept your declaration, some others want at least a ';'
after the } that ends the union, but in either case there is no way to
access the fields of the union by name.

Paul.
-- 
------------------------------------------------------
|debra at research.att.com   | uunet!research!debra     |
------------------------------------------------------



More information about the Comp.unix.questions mailing list