From:	SMTP%"carl@SOL1.GPS.CALTECH.EDU" 30-MAR-1995 08:46:04.33
To:	EVERHART
CC:	
Subj:	Re: [Q] C structures ??

From: carl@SOL1.GPS.CALTECH.EDU (Carl J Lydick)
X-Newsgroups: comp.os.vms
Subject: Re: [Q] C structures ??
Date: 29 Mar 1995 23:10:04 GMT
Organization: HST Wide Field/Planetary Camera
Lines: 50
Distribution: world
Message-ID: <3lcpcc$7av@gap.cco.caltech.edu>
Reply-To: carl@SOL1.GPS.CALTECH.EDU
NNTP-Posting-Host: sol1.gps.caltech.edu
To: Info-VAX@Mvb.Saic.Com
X-Gateway-Source-Info: USENET

In article <1995Mar29.184432@ittpub>, veen@nl101.ittpub.nl (Hans van Veen - ITT Gouden Gids) writes:
=Need some help.....
=
=In FORTRAN you can define the following structure:
=
=	structure	/VMS_Itemlist/
=	 union
=	  map
=	   integer*2	Buflen, Itmcod
=	   integer*4	Bufadr, Retlen
=	  endmap
=	  map
=	   integer*4	Lstend
=	  endmap
=	 endunion
=	endstructure
=	record	/VMS_Itemlist/	Lnm(2)
=
=Allowing to access Buflen and Itmcod separatly (i.e. Lnm(1).Buflen and
=Lnm(1),Itmcod), or via Lnm(2).Lstend (access both words as if it were
=a longword).
=
=How can you do something similar in C ??

Well, since you're posting to comp.os.vms, I'll feel free to use one of DEC's
extensions to C, OK?  Let's see, there are a couple of ways of doing it, the
simplest, and the one that matches your Fortran most closely is:

typedef union                          /* Generic System Service Itemlist */
{	variant_struct
	{	unsigned short buflen;
		unsigned short itmcod;
		unsigned long  bufadr;
		unsigned long  retlen;
	} fubar;
	unsigned long lstend;
} VSS;

The "variant_struct" says that you don't have to use name of that element when
accessing one of its subelements.  If we'd just used a struct, then to refer to
the buflen element, we'd've had to use whatever.fubar.buflen.  With
variant_struct, we can refer simply to whatever.buflen.
--------------------------------------------------------------------------------
Carl J Lydick | INTERnet: CARL@SOL1.GPS.CALTECH.EDU | NSI/HEPnet: SOL1::CARL

Disclaimer:  Hey, I understand VAXen and VMS.  That's what I get paid for.  My
understanding of astronomy is purely at the amateur level (or below).  So
unless what I'm saying is directly related to VAX/VMS, don't hold me or my
organization responsible for it.  If it IS related to VAX/VMS, you can try to
hold me responsible for it, but my organization had nothing to do with it.
