Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: VMS extensions (variant_struct, variant_union) Keywords: VMS C Message-ID: <16783@mimsy.UUCP> Date: 7 Apr 89 14:36:14 GMT References: <1321@Portia.Stanford.EDU> <695@sdrc.UUCP> Distribution: na Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 47 In article <695@sdrc.UUCP> scjones@sdrc.UUCP (Larry Jones) writes: >[These VMS extensions] are structs and unions whose name is omitted >when referring to the members. For example, if you have: > > struct { > int a; > variant_struct { > int x; > int y; > int z; > } vs; > } s; >Then you can (and must!) refer to s.x, s.y, and s.z rather than >s.vs.x, s.vs.y, and s.vs.z. Variant unions work the same way. Curious: if the name cannot be used, why can it be given? It seems to me that this should be struct { int a; variant_struct { ... }; } s; Or can you talk about `s.vs'? At any rate, I usually do something similar for unions using `#define': struct sym { enym symtypes sy_type; union { long syu_integer; char *syu_string; double syu_floating; } sy_un; #define sy_integer sy_un.syu_integer #define sy_string sy_un.syu_string #define sy_floating sy_un.syu_floating }; The only problem with this is that the names `sy_integer', etc., cannot be used from the debugger (which requires instead the long form). But who among us writes bugs, eh? :-) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris