comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: GNAT - return by anonymous access
Date: Wed, 21 Dec 2011 18:33:09 -0600
Date: 2011-12-21T18:33:09-06:00	[thread overview]
Message-ID: <jctts7$69g$1@munin.nbi.dk> (raw)
In-Reply-To: 4ef1cb93$0$7626$9b4e6d93@newsspool1.arcor-online.net

"Georg Bauhaus" <rm.dash-bauhaus@futureapps.de> wrote in message 
news:4ef1cb93$0$7626$9b4e6d93@newsspool1.arcor-online.net...
...
> OP wanted to return an allocated object of limited type (which
> is when GNAT issues its message). If there is a reason for doing
> so (maybe allocating a global library level task at some nested
> level), then what can be done without a redesign?

A redesign is necessary, because what he is trying to do is not likely to 
work on any Ada compiler, and is certainly not going to be portable to other 
Ada compilers (because the language rules aren't consistent).

> (Is everyone happy with dropping return-by-reference for limited
> types? There was a use case for these. I guess it has not
> disappeared, whatever difficulties implementers might have
> encountered...)

We (the ARG) think that is you really need return-by-reference, you should 
write it explicitly using an access type. (And my preference is that access 
type is a pool-specific named access type, otherwise, you'll run into the 
sort of problems the OP did - the rules for anonymous types are a mess.) 
That is, your function should return an access value, not some other type 
where the by-reference nature is hidden (and causes all sort of problems in 
actual use).

Ada 95's rules caused huge problems when you had limited types. In Claw, the 
registry key type is limited, and the effort to create the predefined keys 
was insane: you couldn't declare constants, you could declare a function, 
but you couldn't return an aggregate, you couldn't return a local object, 
you could return a global object -- but that is where we started! -- these 
objects couldn't be constants, they couldn't be initialized with an 
aggregate (either in the declaration or in the package body). We had to 
resort to initializing them component-by-component in the package body - a 
hugely error-prone way of working. Luckily, these things hardly ever change, 
so it was a one-time pain in Claw -- in other circumstances it could be a 
real maintenance problem.

Ada 2005 added build-in-place to solve all of that. But for that to make 
sense, the old scheme had to go, thus we got rid of return-by-reference 
(which never made any sense in the first place).

                                             Randy.







  reply	other threads:[~2011-12-22  0:33 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 [this message]
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
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