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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!reality.xs3.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Interesting Array Initialization Code Gen [FSF GNAT 4.9.2] Date: Mon, 11 May 2015 20:23:11 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <9ee472db-e51d-4e04-a5df-7bee793794a1@googlegroups.com> <42b0aa4e-1002-4ada-af4f-61f996350965@googlegroups.com> NNTP-Posting-Host: rrsoftware.com X-Trace: loke.gir.dk 1431393791 22901 24.196.82.226 (12 May 2015 01:23:11 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 12 May 2015 01:23:11 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:25826 Date: 2015-05-11T20:23:11-05:00 List-Id: wrote in message news:42b0aa4e-1002-4ada-af4f-61f996350965@googlegroups.com... >Just a bit of an update (which probably isn't much of a surprise). > >Assignment produces the same kind of code in the same situations. >Assignments by > function create a new array on the stack, sets the values there, and then > copies it > into the result array. Using a literal value instead just sets the values > directly in the > result array. I'm not sure what the surprise is here (assignment). Ada essentially requires this in any case where the creation of the aggregate (the array value) could fail by an exception, as overriding part but not all of the target is not allowed. In the initialization of a aggregate case, the compiler could have noted the different situation (if the aggregate fails, the allocated object could never be used, so partially initializing it is fine), but I'm not all that surprised that not all compilers do). In any case, you should have avoided the function and written your original question as: Q : Arr_Ptr := new Arr'(for I in Arr'range => I); -- Best, but sorry (see below) except for the minor problem that this syntax (rather needed, IMHO) never made it into Ada (it was proposed for Ada 95, Ada 2005, and is up again for Ada 202x). Maybe it will make it this time. Randy.