comp.lang.ada
 help / color / mirror / Atom feed
From: Lucas Redding <lucas.redding@gmail.com>
Subject: Re: Addressing in Object Ada v/s GNAT (2013) showing Vast Differences
Date: Mon, 21 Sep 2015 04:12:44 -0700 (PDT)
Date: 2015-09-21T04:12:44-07:00	[thread overview]
Message-ID: <26b4bb33-0ebc-4181-bea6-07f1e36ca288@googlegroups.com> (raw)
In-Reply-To: <msrt8o$fdm$1@dont-email.me>

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

  reply	other threads:[~2015-09-21 11:12 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-07 11:39 Addressing in Object Ada v/s GNAT (2013) showing Vast Differences Lucas Redding
2015-09-07 11:54 ` Lucas Redding
2015-09-07 14:04   ` G.B.
2015-09-07 16:02     ` Lucas Redding
2015-09-07 16:28       ` Anh Vo
2015-09-08  7:30         ` Lucas Redding
2015-09-08 15:11           ` Anh Vo
2015-09-08 17:20           ` Jeffrey R. Carter
2015-09-07 17:20   ` Pascal Obry
2015-09-07 17:21   ` Pascal Obry
2015-09-08  7:04     ` Lucas Redding
2015-09-07 21:02   ` Niklas Holsti
2015-09-08  8:00     ` Lucas Redding
2015-09-07 15:48 ` Jeffrey R. Carter
2015-09-08  7:27   ` Lucas Redding
2015-09-08  7:12 ` Markus Schöpflin
2015-09-08  8:05   ` Lucas Redding
2015-09-10 10:47 ` Lucas Redding
2015-09-10 12:34   ` G.B.
2015-09-21 11:12     ` Lucas Redding [this message]
2015-09-21 11:57       ` Jacob Sparre Andersen
2015-09-21 13:22         ` Lucas Redding
2015-09-21 13:47           ` Jacob Sparre Andersen
2015-09-21 13:52           ` Georg Bauhaus
2015-09-21 15:54             ` Lucas Redding
2015-09-22 17:49               ` Jacob Sparre Andersen
2015-09-22 18:45               ` Jacob Sparre Andersen
2015-10-01  6:50                 ` Lucas Redding
2015-09-21 16:48       ` Dmitry A. Kazakov
2015-10-01  7:25         ` Lucas Redding
2015-10-01 20:04           ` Randy Brukardt
replies disabled

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