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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5c89acd494ea9116 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!l22g2000prc.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Self pointer in limited record Date: Fri, 31 Aug 2007 10:37:10 -0700 Organization: http://groups.google.com Message-ID: <1188581830.368058.72900@l22g2000prc.googlegroups.com> References: <1183577468.034566.57830@n60g2000hse.googlegroups.com> <1188578849.187422.280620@50g2000hsm.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1188581831 22242 127.0.0.1 (31 Aug 2007 17:37:11 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 31 Aug 2007 17:37:11 +0000 (UTC) In-Reply-To: <1188578849.187422.280620@50g2000hsm.googlegroups.com> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: l22g2000prc.googlegroups.com; posting-host=66.126.103.122; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news2.google.com comp.lang.ada:1632 Date: 2007-08-31T10:37:10-07:00 List-Id: On Aug 31, 9:47 am, amado.al...@gmail.com wrote: > On 4 Jul, 20:31, Maciej Sobczak wrote: > > > Consider: > > > type T_Access is access all T; > > type T is new Ada.Finalization.Limited_Controlled with record > > Self: T_Access := T'Unchecked_Access; > > -- more components > > -- ... > > end record; > > > I have seen this pattern repeatedly. > > Then you have seen illegal Ada code repeatedly. I wish this were > possible myself. Or more simply: > > type T is -- limited or not > Self : access T := T'Unchecked_Access; > ... > end; > > But the compiler will remind you that Unchecked_Access is not > available for types. No, this can be legal. Normally, you can't apply 'Unchecked_Access to a type name. But within the definition of a type T, the use of T in a context like this refers to the "current instance"; that is, it will refer to whatever object is declared with that type. So if you later declare "X : T;", then the T in T'Unchecked_Access will be replaced by X for that declaration (and X.Self will thus point to X). See 8.6(17). However, it's only legal if T is limited (in Ada 2005, the rule is slightly more restrictive), because 'Unchecked_Access can only be applied to an aliased entity, and 3.10(9) says that the current instance of a *limited* type is defined to be aliased. -- Adam