comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: GNAT - return by anonymous access
Date: Thu, 22 Dec 2011 18:56:01 -0600
Date: 2011-12-22T18:56:01-06:00	[thread overview]
Message-ID: <jd0jj3$1t9$1@munin.nbi.dk> (raw)
In-Reply-To: 8a7d4dc1-69e5-479f-84a3-5c9c7bdd9aae@j10g2000vbe.googlegroups.com

"Simon Belmont" <sbelmont700@gmail.com> wrote in message 
news:8a7d4dc1-69e5-479f-84a3-5c9c7bdd9aae@j10g2000vbe.googlegroups.com...
On Dec 22, 2:11 am, Adam Beneschan <a...@irvine.com> wrote:

>> I think this could be solved by declaring a private type (limited
>> private, if you prefer) to represent an "access" or "handle" or
>> "reference" to test_type.

>That's essentially the path I was taking, but it's doesn't scale well
>(at all, really).  You essentially have to remake every primitive
>operation of the original type for the new faux-access to forward the
>calls so that anything useful could be done.

You could use an Ada 2012 accessor (see 4.1.5 in the draft Ada 2012 RM, or 
AI05-0139-2). It seems that was what you were trying to do (since those 
depend on an access discriminant) -- but the key is, don't, under *ANY* 
circumstances, use an allocator for such a type. Initializing the 
discriminant with an existing object is fine. That's what you'd have to do 
in Ada 95, so I don't really understand why you suddenly changed to using an 
allocator in your Ada 2005 code.

The Ada 95 facility didn't give you any real protection against 
modification, so I don't quite see what you think was lost. But, anyway, use 
the accessor facility: it does give the right lifetime protections.

If you want more detail, I'll be happy to work up an example (but I'll be 
away over the holidays, so not until next week).

                                                     Randy.





  reply	other threads:[~2011-12-23  0:56 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-17 19:17 GNAT - return by anonymous access Simon Belmont
2011-12-17 19:51 ` Simon Wright
2011-12-18  9:08 ` Georg Bauhaus
2011-12-19 23:46 ` Randy Brukardt
2011-12-20  0:14   ` Shark8
2011-12-20 23:18     ` Randy Brukardt
2011-12-21  0:44       ` Simon Belmont
2011-12-21  7:29         ` AdaMagica
2011-12-21 11:05           ` Georg Bauhaus
2011-12-21 11:43             ` AdaMagica
2011-12-21 12:05               ` Georg Bauhaus
2011-12-22  0:33                 ` Randy Brukardt
2011-12-22  0:33           ` Simon Belmont
2011-12-22  7:11             ` Adam Beneschan
2011-12-22 22:11               ` Simon Belmont
2011-12-23  0:56                 ` Randy Brukardt [this message]
2011-12-23 13:20                   ` Simon Belmont
2011-12-27 23:51                     ` Randy Brukardt
2011-12-20 23:53 ` anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox