nolan@Portia.Stanford.EDU (Patrick Nolan) (04/06/89)
Help! I am baffled by some non-standard syntax which I think is a VMS C extension. I have source code for a very VMS-specific program. We are too cheap to buy DEC's compiler, so I am trying to make it work with gcc (1.22). I have run up against some non-standard constructs: variant_union and variant_struct. I tried changing these to union and struct, with disastrous results. Can someone who understands VMS C explain what these things are? -- ======================================================================= Patrick Nolan Bitnet: PLN@SLACVM W. W. Hansen Laboratories Internet: nolan@meggie.stanford.edu Stanford University nolan@portia.stanford.edu
session@uncw.UUCP (Zack Sessions) (04/06/89)
Quoting the VAX-C manual: To illustrate the use of variant aggregates, consider the following code example which doe not use variant aggregates: /* the number on the right represents offsets */ struct TAG_1 { int a; /* 0 */ char *b; /* 4 */ union TAG_2 /* 8 */ { int c; /* 0 */ struct TAG_3 { int d; /* 0 */ int e; /* 4 */ } nested_struct; } nested_union; } enclosing_struct; To access nested member d you would have to use: enclosing_struct.nested_union.nessted_struct.d Using variant aggregates: struct TAG_1 { int a; char *b; variant_union { int c; variant_struct { int d; int e; } nested_struct; } nested_union; } enclosing_struct; Here to access d you would use: enclosing_struct.d To convert to non-variant aggregates it would seem like you would have to expand all references to any member in a variant aggregate to the full reference and use non-variant aggregates. Zack Sessions
scjones@sdrc.UUCP (Larry Jones) (04/07/89)
In article <1321@Portia.Stanford.EDU>, nolan@Portia.Stanford.EDU (Patrick Nolan) writes: > Help! I am baffled by some non-standard syntax which I think is > a VMS C extension. I have source code for a very VMS-specific > program. We are too cheap to buy DEC's compiler, so I am trying > to make it work with gcc (1.22). I have run up against some > non-standard constructs: variant_union and variant_struct. > I tried changing these to union and struct, with disastrous results. > Can someone who understands VMS C explain what these things are? They 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. You should be able to use regular structs or unions instead, but you'll have to change the code to fix all the references. ---- Larry Jones UUCP: uunet!sdrc!scjones SDRC scjones@sdrc.UU.NET 2000 Eastman Dr. BIX: ltl Milford, OH 45150 AT&T: (513) 576-2070 "When all else fails, read the directions."
chris@mimsy.UUCP (Chris Torek) (04/07/89)
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
friedl@vsi.COM (Stephen J. Friedl) (04/09/89)
In article <16783@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes: > > struct sym { > enym symtypes sy_type; ^^^^ bugbugbugbugbugbugbugbugbugbug > > > [...] But who among us writes bugs, eh? :-) Obviously, Chris does :-). Steve -- Stephen J. Friedl / V-Systems, Inc. / Santa Ana, CA / +1 714 545 6442 3B2-kind-of-guy / friedl@vsi.com / {attmail, uunet, etc}!vsi!friedl "I do everything in software, even DMA" - Gary W. Keefe (garyk@telxon)
stuart@bms-at.UUCP (Stuart Gathman) (04/14/89)
To make nested structures and unions manageable, I use one letter names for the nested aggregate. The member names provide the readability. -- Stuart D. Gathman <stuart@bms-at.uucp> <..!{vrdxhq|daitc}!bms-at!stuart>