VMS extensions (variant_struct, variant_union)

Chris Torek chris at mimsy.UUCP
Sat Apr 8 00:36:14 AEST 1989


In article <695 at sdrc.UUCP> scjones at 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 at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list