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,9ce5fb49dc74582f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!m7g2000cwm.googlegroups.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: generic question Date: 21 Nov 2006 07:47:26 -0800 Organization: http://groups.google.com Message-ID: <1164124046.512943.224790@m7g2000cwm.googlegroups.com> References: <1163959439.299036.129940@e3g2000cwe.googlegroups.com> <87mz6nnt4v.fsf@ludovic-brenta.org> <20061119202320.19149a2f@cube.tz.axivion.com> <4560D5BE.5060508@obry.net> <1164059458.442430.110710@j44g2000cwa.googlegroups.com> <4562a51a$0$27404$ba4acef3@news.orange.fr> <4sfrbnFv4ibiU1@mid.individual.net> NNTP-Posting-Host: 66.162.65.129 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1164124052 3613 127.0.0.1 (21 Nov 2006 15:47:32 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 21 Nov 2006 15:47:32 +0000 (UTC) In-Reply-To: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.8) Gecko/20061025 Firefox/1.5.0.8,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: m7g2000cwm.googlegroups.com; posting-host=66.162.65.129; posting-account=Zl1UPAwAAADEsUSm1PMMiDjihtBlZUi_ Xref: g2news2.google.com comp.lang.ada:7609 Date: 2006-11-21T07:47:26-08:00 List-Id: Matthew Heaney wrote: > "Alex R. Mosteo" writes: > > What you did above would be the idiom when you using the package itself to > control allocation of objects: Actually, I might do this differently for tagged vs. non-tagged types: package P is type T (<>) is limited private; type T_Access is access T; function New_T return T_Access; procedure Free (X : in out T_Access); ... end P; At least this way you can set the pointer value to null on return from Free. For tagged types I'd probably do something like: package Q is type T (<>) is tagged limited private; function New_T return not null access T; procedure Free (X : access T'Class); ... private procedure Do_Free (X : access T); ... end; and then implement Free as a dispatching call to Do_Free, which can be overridden by types that derive from T. The reason for declaring Free with type T'Class is that if it were declared as type T, then Free would be primitive for the type. That would make X a controlling operand and hence would have to be non-null. By declaring Free with type T'Class, the operation is no longer primitive, X is not controlling, and so you can pass a null access value without error. You do lose the ability to set the access value to null on return, however. (Yes, you could use named access types, but that defeats the implicit conversions that happen when you use anonymous access types.) In general when you're dealing with hierarchies of tagged types then use anonymous access types, since this facilitates converting among types in the hierarchy.