comp.lang.ada
 help / color / mirror / Atom feed
From: Eryndlia Mavourneen <eryndlia@gmail.com>
Subject: Re: Renaming vs assignment to constant
Date: Fri, 6 Dec 2013 10:06:20 -0800 (PST)
Date: 2013-12-06T10:06:20-08:00	[thread overview]
Message-ID: <573cd67b-b9aa-4337-bedf-b1933ba098a9@googlegroups.com> (raw)
In-Reply-To: <c95e7c9c-6c3b-472b-ac5e-d70538bfc41a@googlegroups.com>

On Friday, December 6, 2013 10:47:03 AM UTC-6, adambe...@gmail.com wrote:
> 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.)
> 
> 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.
> 
>                               -- Adam

I believe "rename" is just that -- creating another name for an entity.  There may be a difference in scope of the new name (possibly more limited), but it seems that there should not be any other differences.  Kind of like a sophisticated version of #define that is syntax- and semantic-smart.

-- Eryndlia Mavourneen (KK1T)

  reply	other threads:[~2013-12-06 18:06 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 [this message]
2013-12-07  0:47   ` Randy Brukardt
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