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 08:54:00 -0700 (PDT)
Date: 2015-09-21T08:54:00-07:00 [thread overview]
Message-ID: <324198e3-3117-48fa-a3d3-aabf54567944@googlegroups.com> (raw)
In-Reply-To: <mtp1ul$rqq$1@dont-email.me>
On Monday, September 21, 2015 at 2:52:10 PM UTC+1, Georg Bauhaus wrote:
> On 21.09.15 15:22, Lucas Redding wrote:
> > On Monday, September 21, 2015 at 12:57:09 PM UTC+1, Jacob Sparre Andersen wrote:
> >> Lucas Redding wrote:
> >>
> >> Your examples don't compile. Please show us the actual code.
> >>
> >> Greetings,
> >>
> >> Jacob
> >> --
> >> "Very small. Go to sleep" - monster (not drooling)
> >
> > Hi Jacob
> >
> > thanks for that. I am avoiding having to flood this with tons of code. So here is a compiled example.
> >
> > package interface_p
> > is
> (...)
> > end INTERFACE_P ;
> >
>
> Is this happening only when you read from the shared location?
> I see the output
> local a: 1, local b: 2
> from the following program, compiled using GNAT GPL 2014 on a Mac:
>
> With Ada.Text_IO;
> with INTERFACE_P; use INTERFACE_P;
> procedure Test_Interface_P
> is
> It : local_rec;
> begin
> It := READ_RECORD;
>
> declare
> use Ada;
> package Xintio is new Text_IO.Integer_IO (sixteen_bits);
> begin
> Text_Io.Put ("local a:"); Xintio.Put (It.a);
> Text_Io.Put (", local b:"); Xintio.Put (It.b);
> Text_Io.New_Line;
> end;
>
> end Test_Interface_P;
Totally agree. Both you and Jacob are correct.
There must be something subtle in my definitions that I am missing.
Note the new code below which reflects the real code except the array of bytes is much larger. I hall keep digging and report back.
Thank you very much.
with SYSTEM ;
package mapping
is
type thirty_two_bits is range 0..(2**31)-1;
for thirty_two_bits'size use 32 ;
for thirty_two_bits'Alignment use 1 ;
type byte_t is range 0..255 ;
for byte_t'size use 8 ;
for byte_t'alignment use 1 ;
type byte_stream is array (0..3) of byte_t ;
for byte_stream'Component_Size use 8 ;
for byte_stream'Alignment use 1;
MAPPED_ARRAY : byte_stream := ( 16#01#, 16#80#,16#0#, 16#0# ) ;
MAPPED_ITEM : thirty_two_bits ;
for MAPPED_ITEM use at MAPPED_ARRAY'Address ;
MAPPED_ITEM_ADDRESS : System.Address := MAPPED_ITEM'Address ;
end mapping ;
with mapping ;
package interface_p
is
type thirty_two_bits is range 0..(2**31)-1;
for thirty_two_bits'size use 32 ;
for thirty_two_bits'Alignment use 1 ;
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 padding_bits is range 0..(2**8)-1 ;
type rec is record
a: fourteen_bits ;
b: ten_bits ;
padding : padding_bits ;
end record ;
for rec use
record
a at 0 range 0..13 ;
b at 0 range 14..23 ;
padding at 0 range 24..31;
end record ;
for rec'size use 32;
for rec'alignment use 1;
subtype local_fourteen_bits is sixteen_bits range 0 .. (2 ** 14)-1;
subtype local_ten_bits is sixteen_bits range 0 .. (2 ** 10)-1;
type local_rec is record
a : local_fourteen_bits ;
b : local_ten_bits ;
end record;
for local_rec use
record
a at 0 range 0 .. 13 ;
b at 2 range 0 .. 9 ;
end record;
for local_rec'size use 32 ;
for local_rec'Alignment use 1 ;
MAPPED_ITEM : thirty_two_bits ;
for MAPPED_ITEM'Address use mapping.MAPPED_ITEM_ADDRESS ;
VAR_REC : rec ;
for VAR_REC use at MAPPED_ITEM'Address ;
-- I explicitly assign here but in actual application it maps onto a 32 bit
-- record in memory. I have deliberately changed in order to avoid adding
-- tons of irrelevant code.
function READ_RECORD
return local_rec ;
end interface_p ;
In the system, the mapping is to an array of bytes populated in memory and then mapped.
next prev parent reply other threads:[~2015-09-21 15:54 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
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 [this message]
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