comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: renames usage
Date: Sat, 2 Jan 2021 21:19:49 -0600	[thread overview]
Message-ID: <rsrd4m$i07$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: rsnckg$h6v$1@dont-email.me

"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message 
news:rsnckg$h6v$1@dont-email.me...
> On 1/1/21 1:39 PM, DrPi wrote:
>>
>> Reading all the answers, I understand that :
>>  X : Float renames Random (Seed);
>> is equivalent to :
>>  X : constant Float := Random (Seed);
>
> Technically, the renames gives a name to the anonymous temporary object 
> returned by the function. The constant declaration makes a constant copy 
> of it. So they're equivalent, but not identical.
>
> However, the compiler is free to optimize the copy away, and I'd be 
> surprised if there are any compilers that don't (except GNAT with -O0).

In this case (a scalar return), the "copy" is a register, and it would be 
hard (and pointless) to eliminate that. It's more interesting for a function 
that returns a composite object, and in that case your answer is correct. 
Note that you can tell if a copy is made if there is a controlled component 
in the object.

One thing we've learned in language design is that nothing is ever exactly 
equivalent to something else. There's always subtle differences. Typical 
programmers can ignore such stuff, but not language designers.

                            Randy.


  parent reply	other threads:[~2021-01-03  3:19 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-31 11:48 renames usage DrPi
2020-12-31 12:10 ` John Perry
2020-12-31 13:31   ` DrPi
2020-12-31 12:33 ` Gautier write-only address
2020-12-31 14:49 ` Jeffrey R. Carter
2020-12-31 15:55   ` DrPi
2020-12-31 18:48     ` Dmitry A. Kazakov
2021-01-01 12:39       ` DrPi
2021-01-01 13:20         ` Dmitry A. Kazakov
2021-01-02 11:53           ` DrPi
2021-01-01 14:46         ` Jeffrey R. Carter
2021-01-02 11:55           ` DrPi
2021-01-03  3:19           ` Randy Brukardt [this message]
2021-01-03 10:05             ` Jeffrey R. Carter
2021-01-06  2:49               ` Randy Brukardt
2021-01-02 16:00         ` G.B.
2021-01-02 17:22           ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox