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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.182.247.39 with SMTP id yb7mr16949822obc.38.1442833964677; Mon, 21 Sep 2015 04:12:44 -0700 (PDT) X-Received: by 10.182.52.132 with SMTP id t4mr76410obo.25.1442833964654; Mon, 21 Sep 2015 04:12:44 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!kq10no6955588igb.0!news-out.google.com!n2ni7461igy.0!nntp.google.com!kq10no6955577igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 21 Sep 2015 04:12:44 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=194.138.39.55; posting-account=IcHmbgoAAABVfpbjrkJyy4Yb3hmce3tn NNTP-Posting-Host: 194.138.39.55 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <26b4bb33-0ebc-4181-bea6-07f1e36ca288@googlegroups.com> Subject: Re: Addressing in Object Ada v/s GNAT (2013) showing Vast Differences From: Lucas Redding Injection-Date: Mon, 21 Sep 2015 11:12:44 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:27796 Date: 2015-09-21T04:12:44-07:00 List-Id: On Thursday, September 10, 2015 at 1:34:17 PM UTC+1, G.B. wrote: > On 10.09.15 12:47, Lucas Redding wrote: > > I need to change the alignment of each underlying type mapped into memory. I am hoping the combination of explicit alignments and precise rep clauses (size etc.) should make the code portable between compilers. > > You are certainly aware of mappings that can be effected > by just using a type conversion? This way, some of the less > portable representations can be stashed away. > > package P is > > type T1 is range 1 .. 10; > type T2 is range -1_000 .. +1_000; > > type Internal is record > A : T1; > B : T2; > end record; > > type Mapped is new Internal; > > for Mapped'Size use 32; > for Mapped'Alignment use 1; > for Mapped use record > A at 0 range 0 .. 7; > B at 0 range 11 .. 30; > end record; > > end P; > > with P; > procedure Test_P is > Z : P.Mapped; > pragma Volatile (Z); > > procedure Place (Value : P.Internal) is > begin > Z := P.Mapped (Value); > pragma Inspection_Point (Z); > end Place; > > begin > Place( P.Internal'(A => 3, B => 42) ); > end Test_P; Thanks GB, In fact I am stumbling on portability of the rep clauses. But I think more importantly I am led to feel that GNAT is not enforcing the strong typing and thus the "Deterministic" properties that Ada boasts. I have the following type specifications which map onto an input source we have no control over: type sixteen_bits is range 0..(2**16)-1 ; type fourteen_bits is range 0..(2**14)-1; type ten_bits is range 0..(2**10)-1; type rec is record a: fourteen_bits ; b: ten bits ; end rec ; for rec use a at 0 range 0..13 ; b at 0 range 14..23 ; end rec ; for rec'size use 32; for rec'alignment use 1; I declare the variable VAR_REC : rec ; for VAR_REC;'Address use Mapped_input_item'Address ; We would like to copy the information once to a byte aligned record to hopefully speed up access to this item because it is accessed internally a large number of times. so our local type specification is subtype local_fourteen_bits is sixteen_bits range 0..(2**14)-1; subtype local_ten_bits is sixteen_bits range (2**16)-1; type local_rec is record local_a : local_fourteen_bits ; local_b : local_ten_bits ; end record; for local_rec use local_a at 0 range 0..13 ; local_b at 2 range 0..9 ; end record; for local_rec'size use 32 ; for local_rec'Alignment use 1 ; I declare the variable VAR_LOCAL_REC : local_rec ; The problem is when I copy each record component to the local copies (including the typecast) my var_local_rec.a takes on a 16 bit value and thus includes the bit values from var_rec.b ; So if var_rec.a is 1 and var_rec.b is 2 I end up with the following in var_local_rec in GNAT Ada: var_local_rec.a = 32769 ; var_local_rec.b = 2 ; Clearly this is wrong. And although I have set all checks in the compiler I don't get an overflow error which is what I would expect. In Object Ada I get: var_local_rec.a = 1 ; var_local_rec.b = 2; ...which is what I'd expect given the strongly typed definitions. Am I missing something here? Is there a pragma or compiler switch that enforces the strict typing regime? Any continued help is greatly appreciated. Lucas