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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,aa14979d20ba3045 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!s20g2000vbp.googlegroups.com!not-for-mail From: sjw Newsgroups: comp.lang.ada Subject: Re: Use aggregates (Was: Allocation question) Date: Mon, 11 May 2009 14:26:40 -0700 (PDT) Organization: http://groups.google.com Message-ID: <8a88003e-b3d4-4e6f-8bff-bb993c6e540f@s20g2000vbp.googlegroups.com> References: <4a07fc7a$0$2855$ba620e4c@news.skynet.be> <87prefhq04.fsf@nbi.dk> <62aa80a1-1c0b-4716-ab16-9b6243d97ff2@o27g2000vbd.googlegroups.com> NNTP-Posting-Host: 82.20.239.89 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1242077201 7906 127.0.0.1 (11 May 2009 21:26:41 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 11 May 2009 21:26:41 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s20g2000vbp.googlegroups.com; posting-host=82.20.239.89; posting-account=_RXWmAoAAADQS3ojtLFDmTNJCT0N2R4U User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:5771 Date: 2009-05-11T14:26:40-07:00 List-Id: On May 11, 1:16=A0pm, Ludovic Brenta wrote: > Jacob Sparre Andersen wrote on comp.lang.ada: > > > > > Olivier Scalbert wrote: > > > procedure Fill(Image: in out Image_T; Color: Color_T) is > > > begin > > > =A0 =A0 =A0 for x in Image'range(1) loop > > > =A0 =A0 =A0 =A0 =A0 for y in Image'range(2) loop > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 Image(x,y) :=3D Color; > > > =A0 =A0 =A0 =A0 =A0 end loop; > > > =A0 =A0 =A0 end loop; > > > end Fill; > > > I would sugges that you rather wrote this: > > > =A0 =A0Image :=3D (others =3D> (others =3D> Color)); > > > It is a more precise expression of what (I guess) you want done, and > > thus it gives the compiler more precise information to work with. > > This is not always a good idea. On some targets, GNAT places the > aggregate on the stack and this can raise a Storage_Error. In avionics > programs, I remember replacing aggregates with loops for this reason. Someone recently found it was quicker to test an array for some condition by looping through it rather than by comparing with an aggregate [eg X =3D (others =3D> 0)]. I had naively assumed that GNAT would just do the comparisons of the elements of X against 0, as the hand-crafted loop does, rather than construct a whole array of zeros on the stack and then loop through that ...