From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,35af79fb6fbb1bb2 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!69.16.177.246.MISMATCH!cyclone03.ams.highwinds-media.com!news.highwinds-media.com!npeersf02.ams.highwinds-media.com!newsfe12.ams2.POSTED!40385e62!not-for-mail From: Per Sandberg User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Problem with representation clause in gnat 4.3 References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <2CFFk.138$my.115@newsfe12.ams2> X-Complaints-To: abuse@WWWSpace.NET NNTP-Posting-Date: Sat, 04 Oct 2008 08:14:54 UTC Date: Sat, 04 Oct 2008 10:10:39 +0000 Xref: g2news2.google.com comp.lang.ada:7954 Date: 2008-10-04T10:10:39+00:00 List-Id: 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?