From: Per Sandberg <per.sandberg@bredband.net>
Subject: Re: Problem with representation clause in gnat 4.3
Date: Sat, 04 Oct 2008 10:10:39 +0000
Date: 2008-10-04T10:10:39+00:00 [thread overview]
Message-ID: <2CFFk.138$my.115@newsfe12.ams2> (raw)
In-Reply-To: <gc655v$702$1@online.de>
Hi
Think this has to do with the implicit alignment of the record, in the
first case the integer (integers has a default alignment of 4)
components are aligned to word boundaries breaking their default
alignment resulting in an alignment of 2 for the record as whole.
In the second case the integers are aligned to dword boundaries in the
record resulting in a propagation of the default alignment of 4 for the
integers the record.
So if you add an alignment clause "for Compound'Alignment use 2" the
compiler will do what you want.
Haven't tested it since I don't run "Debian Lenny".
/Hope it helps
/Per
Michael Bode wrote:
> 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?
next prev parent reply other threads:[~2008-10-04 10:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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