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: a07f3367d7,3ef3e78eacf6f938 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!c14g2000yqm.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Making a nonlimited type controlled by means of a controlled component Date: Tue, 28 Jul 2009 02:48:39 -0700 (PDT) Organization: http://groups.google.com Message-ID: <31bb0f0b-9655-4bda-81c3-e8f7855a1ee9@c14g2000yqm.googlegroups.com> References: NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1248774520 16321 127.0.0.1 (28 Jul 2009 09:48:40 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 28 Jul 2009 09:48:40 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c14g2000yqm.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.6) Gecko/2009012111 Red Hat/3.0.6-1.el5 Firefox/3.0.6,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:7373 Date: 2009-07-28T02:48:39-07:00 List-Id: AdaMagica wrote on comp.lang.ada: > Hu Ludovic , > > that's dangerous what you proposed: > ----------------------------------- > private with Ada.Finalization; > > package Ludovic is > > =A0 type T is private; > > =A0 -- primitive operations here > =A0 procedure Show (X: in T); > > private > > =A0 type Controller (Enclosing: access T) is new > Ada.Finalization.Controlled with null record; > > =A0 overriding procedure Initialize (This: in out Controller); > =A0 overriding procedure Adjust =A0 =A0 (This: in out Controller); > =A0 overriding procedure Finalize =A0 (This: in out Controller); > > =A0 type T is record -- note: untagged record > =A0 =A0 C: Controller (Enclosing =3D> T'Access); > =A0 =A0 I: Integer; > =A0 end record; > > end Ludovic; > with Ada.Text_IO; > use =A0Ada.Text_IO; > > package body Ludovic is > > =A0 I: Integer :=3D 0; > > =A0 overriding procedure Initialize (This: in out Controller) is > =A0 begin > =A0 =A0 I :=3D I + 1; > =A0 =A0 This.Enclosing.I :=3D I; > =A0 end Initialize; > > =A0 overriding procedure Adjust (This: in out Controller) is > =A0 begin > =A0 =A0 This.Enclosing.I :=3D This.Enclosing.I + 1; > =A0 end Adjust; > > =A0 overriding procedure Finalize (This: in out Controller) is > =A0 begin > =A0 =A0 null; > =A0 end Finalize; > > =A0 procedure Show (X: in T) is > =A0 begin > =A0 =A0 Put_Line (Integer'Image (X.I) & Integer'Image (X.C.Enclosing.I)); > =A0 end Show; > > end Ludovic; > with Ada.Text_IO; > use =A0Ada.Text_IO; > > with Ludovic; > > procedure Brenta is > > =A0 X, Y: Ludovic.T; > > begin > > =A0 Ludovic.Show (X); > =A0 Ludovic.Show (Y); > =A0 New_Line; > > =A0 X :=3D Y; > =A0 Ludovic.Show (X); =A0-- X.C points to Y - that's surely not what you > want. > =A0 Ludovic.Show (Y); > =A0 New_Line; > > end Brenta; Darn, you're right. I hadn't thought of that. Now I understand why Ada 95 requires T to be limited (in this case the problem goes away, since assignment is forbidden). What worries me the most is that AI402, which allowed access discriminants on nonlimited types, does not mention this issue at all. http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ais/ai-00402.txt?rev=3D1.5 Randy, do you have an opinion on this, or should I raise the problem with the ARG? -- Ludovic Brenta.