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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6eeec5ea37e964f0 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Representation clauses and records Date: 1997/11/25 Message-ID: #1/1 X-Deja-AN: 292541722 References: <347000b1.4909762@news.geccs.gecm.com> <3475F02C.5585B1B6@aonix.com> <347a8dc3.3438484@news.geccs.gecm.com> Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-11-25T00:00:00+00:00 List-Id: 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 (818) 985-1271