comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: Representation clauses and records
Date: 1997/11/25
Date: 1997-11-25T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023680002511970714290001@news.ni.net> (raw)
In-Reply-To: 347a8dc3.3438484@news.geccs.gecm.com


In article <347a8dc3.3438484@news.geccs.gecm.com>, brian.orpin@gecm.dot.com
wrote:


>So the 'mod at' is forcing the compiler to align each of the records on a
>longword boundary.  I hadn't considered the effect of putting those
>elements in an array :-(.  Does mod 4 always align on longword and is mod
>1 always a byte boundary?  

That's what at mod 4 does: align on a longword boundary; that's the
definition.  What else could it do?

I'm not sure at mod 1 does anything - it's the same as not specifying a mod
clause at all.

>
>If you use mod 1 does the compiler not get confused with a 0..31 rep
>clause?  

mod 1 and 0 .. 31 are different things.  All the mod is doing is stating a
characteristic of the address of a 4 byte object (that it can be any
address, because any address divided by 1 is the itself).  The range part
of the rep clause is stating the location of a component within the object
- relative to the start of the object.


>type Byte is Integer range 0..255;

This is incorrect: I think you meant

type Byte is range 0 .. 255;

But why not use type Interfaces.Unsigned_8?

>for type Byte'Size use 8;
>
>type Four_Bytes is
>record
>        byte_one : byte;
>        byte_two : byte;
>        byte_three : byte;
>        byte_four : byte;
>end record;
>
>then use either
>
>for Four_Bytes use record
>at mod 1
>        byte_one at 0 range 0..7;
>        byte_two at 1 range 0..7;
>        byte_three at 2 range 0..7;
>        byte_four at 3 range 0..7;
>end record;
>
>for Four_Bytes use record
>at mod 4
>        byte_one at 0 range 0..7;
>        byte_two at 0 range 8..15;
>        byte_three at 0 range 16..23;
>        byte_four at 0 range 24..31;
>end record;

This is confused.  Never use mod 1.  And besides, it has nothing to do with
the rest of the rep clause.

What do you require: that objects of the type be aligned on a four-byte
boundary?  If so, then say at mod 4.  Do you have no alignment
requirements?  If so, then say nothing.

If you want to place each component of the record at successive bytes, then
either rep clause above will do.  The rep clause states where each byte
component is relative to the start of the record, but this is different
from the mod clause, which aligns the entire record.

>Am I right in thinking that both these examples are valid and there is no
>real difference between them for a 32 bit system.  The mapping of the
>bytes onto memory is important.

The examples are only different wrt the mod clause - the rep clauses are
equivalent.

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




  parent reply	other threads:[~1997-11-25  0:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <347000b1.4909762@news.geccs.gecm.com>
1997-11-21  0:00 ` Representation clauses and records Brian Nettleton
1997-11-21  0:00   ` Matthew Heaney
1997-11-21  0:00   ` Brian Nettleton
1997-11-24  0:00     ` Martin M Dowie
1997-11-25  0:00       ` Robert Dewar
1997-11-27  0:00         ` Martin M Dowie
     [not found]   ` <347a8dc3.3438484@news.geccs.gecm.com>
1997-11-25  0:00     ` Matthew Heaney [this message]
1997-12-16  0:00 ` Pascal MALAISE
1997-12-16  0:00   ` Larry Kilgallen
1997-12-17  0:00     ` Pascal MALAISE
1997-12-18  0:00       ` David J. Fiander
1997-12-18  0:00         ` Tucker Taft
1997-12-18  0:00         ` Robert Dewar
replies disabled

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