comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Renaming vs assignment to constant
Date: Fri, 6 Dec 2013 18:47:37 -0600
Date: 2013-12-06T18:47:37-06:00	[thread overview]
Message-ID: <l7tr79$oc8$1@loke.gir.dk> (raw)
In-Reply-To: c95e7c9c-6c3b-472b-ac5e-d70538bfc41a@googlegroups.com

<adambeneschan@gmail.com> wrote in message 
news:c95e7c9c-6c3b-472b-ac5e-d70538bfc41a@googlegroups.com...
On Friday, December 6, 2013 7:14:51 AM UTC-8, Simon Wright wrote:
>> A poster on Stack Overflow wrote
>>
>>    Now : Time renames Clock;
>>
>> (using Ada.Calendar) which made me blink until I realised that it is the
>> equivalent of
>>
>>    Now : constant Time := Clock;
>>
>> GNAT generates the same code for these two forms. Is there a difference?
>>
>> Which form is preferred?
>
>I prefer the second form, mostly because in the first one, Time does not 
>"rename" anything the
>same way that a variable that renames another variable, or a function that 
>renames another
>function, does.  (Technically, I think Time renames an anonymous object 
>created by the compiler
>to hold the function result, although it seems like incorrect English to 
>talk about "renaming"
>something that didn't have a name in the first place.)

Be glad that we didn't introduce named anonymous access types. :-) [We 
seriously considered that, to allow named types with dynamic accessibility 
and the special anonymous access-to-subprogram rules, but decided it was 
just too weird.]

>However, there *might* be a difference between the two forms if the type 
>involved is (1) a task type
>or a type that contains a task as a subcomponent, (2) a controlled type or 
>a type that contains one,
>(3) something with a coextension.  I'm really not sure whether there's a 
>difference in any of these
>cases, and #2 may be a case where some of the differences are or were 
>dependent on the
>implementation (because of build-in-place semantics).  I'd have to do some 
>research to figure
>out if there are any differences.  Maybe Randy already knows the answer. 
>Also, there may be
>differences related to accessibility levels.  In this simple case that 
>doesn't involve any of those
>features, I don't think there's a semantic difference.

Any differences in (1) and (2) would be because there is a difference in 
accessibility levels. I think there is such a difference, but you're not 
going to talk me into a trip into the Heart-of-Darkness (3.10.2) to figure 
it out!

In general, the difference between:

   R : <something> renames <name>;

and

  C : constant <something> := <name>;

is that the former is essentially by reference (and any constraints on 
<something> are ignored, a terrible Ada 83 decision made mainly because they 
didn't want to introduce a complex concept like static matching -- which of 
course the Ada 95 team decided had to be introduced, so there are no 
language complexity savings and a lot of confusion over the meaning) and the 
latter is essentially by-copy (a copy of <name> is made).

For the function call case, the thing being renamed is an anonymous return 
object, so the difference isn't really noticable, especially with the 
various permissions and requirements to eliminate those objects.

                             Randy.




  parent reply	other threads:[~2013-12-07  0:47 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-06 15:14 Renaming vs assignment to constant Simon Wright
2013-12-06 16:09 ` Jeffrey Carter
2013-12-06 18:03   ` AdaMagica
2013-12-06 18:24     ` Jeffrey Carter
2013-12-06 16:47 ` adambeneschan
2013-12-06 18:06   ` Eryndlia Mavourneen
2013-12-07  0:47   ` Randy Brukardt [this message]
2013-12-07  1:55     ` Shark8
2013-12-06 18:35 ` G.B.
2013-12-06 20:07   ` adambeneschan
2013-12-06 21:59 ` Shark8
2013-12-06 23:48   ` adambeneschan
2013-12-07  1:04     ` Shark8
2013-12-07  1:26       ` adambeneschan
2013-12-07  6:17       ` J-P. Rosen
2013-12-07  6:22         ` J-P. Rosen
2013-12-07  8:57   ` Dmitry A. Kazakov
2013-12-07  9:02     ` Dmitry A. Kazakov
replies disabled

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