From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d000078cf0ac6305 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-09-11 11:40:17 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!wn1feed!wn2feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc53.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Learning Ada-What does this mean. References: X-Newsreader: Tom's custom newsreader Message-ID: NNTP-Posting-Host: 12.234.13.56 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc53 1031769616 12.234.13.56 (Wed, 11 Sep 2002 18:40:16 GMT) NNTP-Posting-Date: Wed, 11 Sep 2002 18:40:16 GMT Organization: AT&T Broadband Date: Wed, 11 Sep 2002 18:40:16 GMT Xref: archiver1.google.com comp.lang.ada:28831 Date: 2002-09-11T18:40:16+00:00 List-Id: > type T_MEM_IO is > record > ... This declares a record structure called T_MEM_IO. > for T_MEM_IO use > record > INT_1 at 0 range 0..31; > INT_2 at 1 range 0..31; > end record; This "record representation clause" tells the compiler you want the record laid out in memory in a certain way (otherwise the compiler could move things around or leave empty filler bytes for instance). This particular one says that INT_1 should start at the first "storage element" and occupy its first 32 bits. INT_2 should start at the second storage element and occupy its first 32 bits. > 2)The code shown above is compiling perfectly when compiled using > tartan compiler(on AIX), but giving error when compiled using gnat(on > windows 2000).Why is it so? If a "storage element" on the target machine is 32 bits wide, then the first one will hold INT_1 and the second INT_2. Is a storage element on AIX 32 bits wide? On a PC a "storage element" is an 8 bit byte, so INT_1 occupies the first 4 bytes. INT_2 starts at the second byte, ie, 1/4 of the way into INT_1, and takes the next 4 bytes. So INT_1 and INT_2 overlap on a PC. This is illegal, and the Gnat compilation error message ought to be telling you that. For the PC you probably want instead for T_MEM_IO use record INT_1 at 0 range 0..31; INT_2 at 4 range 0..31; end record; so INT_2 starts right after INT_1. But why have a representation clause at all? If the record is used purely internally, and not read/written by other programs, the OS, or hardware, then you probably don't care how the compiler laid out the record, and you might as well let it perform any optimization tricks it knows. If the record is shared with the outside world, then you may have to worry about things like endianness which might be different between a PC and an AIX. The name "T_MEM_IO" suggests this record might indeed be something used by a hardware device - is that going to work the same on the PC as the AIX?