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: border1.nntp.dca.giganews.com!nntp.giganews.com!goblin2!goblin.stu.neva.ru!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: Renaming vs assignment to constant Date: Fri, 6 Dec 2013 18:47:37 -0600 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: loke.gir.dk 1386377258 24968 69.95.181.76 (7 Dec 2013 00:47:38 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Sat, 7 Dec 2013 00:47:38 +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: number.nntp.dca.giganews.com comp.lang.ada:184118 Date: 2013-12-06T18:47:37-06:00 List-Id: 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 : renames ; and C : constant := ; is that the former is essentially by reference (and any constraints on 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 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.