comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: Learning Ada-What does this mean.
Date: Wed, 11 Sep 2002 18:40:16 GMT
Date: 2002-09-11T18:40:16+00:00	[thread overview]
Message-ID: <k6Mf9.76945$Jo.17889@rwcrnsc53> (raw)
In-Reply-To: d40d7104.0209110358.50df45fa@posting.google.com

>  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?



  parent reply	other threads:[~2002-09-11 18:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-11 11:58 Learning Ada-What does this mean prashna
2002-09-11 12:26 ` Georg Bauhaus
2002-09-13  4:24   ` prashna
2002-09-13 12:46     ` Georg Bauhaus
2002-09-11 14:04 ` Stephen Leake
2002-09-11 14:31 ` Pascal Obry
2002-09-11 14:50   ` Peter Hermann
2002-09-11 18:40 ` tmoran [this message]
2002-09-13  4:19   ` prashna
2002-09-13  4:52     ` tmoran
2002-09-13 11:00     ` David C. Hoos, Sr.
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox