From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Interesting Array Initialization Code Gen [FSF GNAT 4.9.2]
Date: Mon, 11 May 2015 20:23:11 -0500
Date: 2015-05-11T20:23:11-05:00 [thread overview]
Message-ID: <mirklv$mbl$1@loke.gir.dk> (raw)
In-Reply-To: 42b0aa4e-1002-4ada-af4f-61f996350965@googlegroups.com
<visaoni@gmail.com> 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.
prev parent reply other threads:[~2015-05-12 1:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-11 18:02 Interesting Array Initialization Code Gen [FSF GNAT 4.9.2] visaoni
2015-05-11 22:45 ` visaoni
2015-05-12 1:23 ` Randy Brukardt [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox