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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.43.94.71 with SMTP id bx7mr7149989icc.2.1399017529980; Fri, 02 May 2014 00:58:49 -0700 (PDT) X-Received: by 10.140.94.75 with SMTP id f69mr861qge.30.1399017529941; Fri, 02 May 2014 00:58:49 -0700 (PDT) Path: border2.nntp.dca3.giganews.com!backlog4.nntp.dca3.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!c1no430818igq.0!news-out.google.com!dz10ni28916qab.1!nntp.google.com!j15no103861qaq.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 2 May 2014 00:58:49 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=91.7.63.170; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf NNTP-Posting-Host: 91.7.63.170 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <21e0e1f0-3fe4-4c5a-8e01-21691a0207f4@googlegroups.com> Subject: Re: How to declare a generic formal type "covered" by another? From: AdaMagica Injection-Date: Fri, 02 May 2014 07:58:49 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Original-Bytes: 2233 Xref: number.nntp.dca.giganews.com comp.lang.ada:186189 Date: 2014-05-02T00:58:49-07:00 List-Id: > Most smart-pointer packages expose the access type; see, for example, > > http://www.oopweb.com/Ada/Documents/AdaLinux/Volume/18.html > http://www.adacore.com/adaanswers/gems/gem-97-reference-counting-in-ada-part-1/ But exposing the access type is bad since pointes may easily outlive the object they point to. Let Get return the access value of the smart pointer P and let P be the only pointer to the object accessed. Let Q be another smart pointer. declare Obj: access Client_Data'Class := Get (P); begin My_Data (Obj.all).I := 2012; -- No problem. P := Q; -- Frees the original object, -- because the reference count -- is zero after this operation. My_Data (Obj.all).I := 95; -- Oops - writing freed memory! end; See also: http://www.adacore.com/adaanswers/gems/gem-107-preventing-deallocation-for-reference-counted-types/