comp.lang.ada
 help / color / mirror / Atom feed
* Problem with representation clause in gnat 4.3
@ 2008-10-03 22:08 Michael Bode
  2008-10-04  2:36 ` Randy Brukardt
  2008-10-04 10:10 ` Per Sandberg
  0 siblings, 2 replies; 5+ messages in thread
From: Michael Bode @ 2008-10-03 22:08 UTC (permalink / 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?



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-10-04 12:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-03 22:08 Problem with representation clause in gnat 4.3 Michael Bode
2008-10-04  2:36 ` Randy Brukardt
2008-10-04 12:36   ` Michael Bode
2008-10-04 10:10 ` Per Sandberg
2008-10-04 12:37   ` Michael Bode

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