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: a07f3367d7,aa14979d20ba3045 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!feeder.erje.net!nuzba.szn.dk!news.jacob-sparre.dk!pnx.dk!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Use aggregates (Was: Allocation question) Date: Tue, 12 May 2009 16:18:50 -0500 Organization: Jacob Sparre Andersen Message-ID: References: <4a07fc7a$0$2855$ba620e4c@news.skynet.be> <87prefhq04.fsf@nbi.dk> <62aa80a1-1c0b-4716-ab16-9b6243d97ff2@o27g2000vbd.googlegroups.com> <26af755b-0b90-429f-a688-86bf307da2b5@o20g2000vbh.googlegroups.com> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1242163143 11757 69.95.181.76 (12 May 2009 21:19:03 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 12 May 2009 21:19:03 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5512 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 Xref: g2news2.google.com comp.lang.ada:5801 Date: 2009-05-12T16:18:50-05:00 List-Id: "Martin" wrote in message news:26af755b-0b90-429f-a688-86bf307da2b5@o20g2000vbh.googlegroups.com... >> 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. > >And not just GNAT...in fact, I'm struggling to remember a compiler >that _doesn't_ do the "large and slow (and stupid?)" aggregate for >assignment (or initialisation). You must have not used many Ada compilers. I known that I personally wrote some 6000 lines of code to handle avoiding aggregate temporaries in Janus/Ada, and that was done after noting that most of the other Ada compilers that we tried did a much better job of it. Indeed, I've very dubious that GNAT does not do it in most cases. But it is important to realize that Ada's rules about what does and does not get modified in an assignment can prevent such an optimization. The reason I had to write so much code was to detect all of the cases where the optimization cannot be done safely (safely in an Ada sense; the original programmer probably wouldn't care about the different), such as assigning different parts of the target object, certain exception cases, and the like. Truely simple cases, such as (others => 0) when the constraint is static surely always should get done, but there are a lot of cases in the grey areas. In any case, Ada compiler vendors don't make their compilers worse than necessary for no reason. There are a lot of things that can prevent optimizations, they're not because the vendor is "lazy". You could optimize without any of the rules Ada has, but the resulting program would not have very predictable results. That's a big deal for safety-critical uses, and (for me at least) important so that I can use optimization and no worry about whether it is going to change the behavior of the program in an important way. Randy.