comp.lang.ada
 help / color / mirror / Atom feed
From: Michael Bode <m.g.bode@web.de>
Subject: Problem with representation clause in gnat 4.3
Date: Sat, 04 Oct 2008 00:08:54 +0200
Date: 2008-10-04T00:08:54+02:00	[thread overview]
Message-ID: <gc655v$702$1@online.de> (raw)

Hi,

I've a problem with a representation that I don't understand. And I'm
pretty sure older versions of gnat than 4.3 had a different behaviour.

This stuff compiles as I expect with gnat 4.3 (on Debian Lenny):

with Ada.Text_Io;

procedure Align is

   type Compound is record
      A : Boolean;
      B : Integer;
      C : Integer;
   end record;
   for Compound use record
      A at 0 range 0 .. 0;
      B at 2 range 0 .. 31;
      C at 6 range 0 .. 31;
   end record;

   type C_Array is array (Natural range <>) of Compound;
   for C_Array'Component_Size use 80;

   Size : Natural := Compound'Size;
begin
   Ada.Text_Io.Put_Line ("Compound has size" & Natural'Image(Size));
end Align;

~/myprogs/test $ gnatmake align
gcc-4.3 -c align.adb
gnatbind -x align.ali
gnatlink align.ali
~/myprogs/test $ ./align 
Compound has size 80
~/myprogs/test $ 

Now if I move component A of the record to the end as in
...
   type Compound is record
      B : Integer;
      C : Integer;
      A : Boolean;
   end record;
   for Compound use record
      B at 0 range 0 .. 31;
      C at 4 range 0 .. 31;
      A at 8 range 0 .. 0;  
   end record;
...

~/myprogs/test $ gnatmake align
gcc-4.3 -c align.adb
align.adb:16:09: component size for "C_Array" too small, minimum allowed is 96
gnatmake: "align.adb" compilation error
~/myprogs/test $ 

And if i remove the line 'for C_Array'Component_Size use 80;' so the
program compiles I get

~/myprogs/test $ gnatmake align
gcc-4.3 -c align.adb
gnatbind -x align.ali
gnatlink align.ali
~/myprogs/test $ ./align 
Compound has size 65

So we see Compound should definitivly fit into 80 bits.

Obviously gnat wants to align to DWORD boundaries in the 2nd case but
not in the 1st. Why and what can I do about it?



             reply	other threads:[~2008-10-03 22:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-03 22:08 Michael Bode [this message]
2008-10-04  2:36 ` Problem with representation clause in gnat 4.3 Randy Brukardt
2008-10-04 12:36   ` Michael Bode
2008-10-04 10:10 ` Per Sandberg
2008-10-04 12:37   ` Michael Bode
replies disabled

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