Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!att!tut.cis.ohio-state.edu!ucsd!ames!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Need help with union trick: summary of replies Message-ID: <28949@mimsy.umd.edu> Date: 6 Jan 91 17:16:48 GMT References: <1991Jan4.192645.7094@lavaca.uh.edu> <4977:Jan422:17:0191@kramden.acf.nyu.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 37 In at least two articles at least two people write about >ANSI anonymous structures but X3.159-1989 does not have what these people mean. The idea, which is supported by a number of `C-like' compilers, is to allow union (and structure) definitions of the form struct value { enum { integer, floating } v_kind; union { int v_integer; /* value if integer */ float v_floating; /* value if floating */ }; } v; after which references of the form `v.v_integer' would be allowed. Although this is useful, it is not part of `ANSI C'. Some people use workarounds that look like: struct value { enum { integer, floating } v_kind; union { int vu_integer; float vu_floating; } v_un; #define v_integer v_un.vu_integer #define v_floating v_un.vu_floating } v; which causes a reference of the form `v.v_integer' to expand to one of the form `v.v_un.vu_integer'. Other people type in the extra `un.vu_' every time (to emphasize the union). -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris