comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Ada 2012 : aliased parameters ?
Date: Sat, 30 Apr 2011 18:46:57 -0500
Date: 2011-04-30T18:46:57-05:00	[thread overview]
Message-ID: <ipi71l$cl2$1@munin.nbi.dk> (raw)
In-Reply-To: 87y62ra8uz.fsf@mid.deneb.enyo.de

"Florian Weimer" <fw@deneb.enyo.de> wrote in message 
news:87y62ra8uz.fsf@mid.deneb.enyo.de...
...
>> The advantage of the aliased parameters is that they eliminate the 
>> runtime
>> checks by forcing the checks to the call site (where they can be 
>> statically
>> made 99% of the time).
>
> I'm wondering if it is necessary that the returned limited record is
> controlled, so that a reference counter can be incremented and later
> decremented to ensure that the access discriminant does not become
> dangling.  That would make the whole thing a bit clumsy to use, and
> come with quite a bit of run-time overhead.

It's not required, but that is the way it will be used in the containers (so 
that the tampering check can apply only so long as the access exists). One 
hopes that compilers will work to minimize the overhead in this case (the 
non-list finalization implementation that GNAT is supposedly getting will be 
ideal for such cases).

>> The intent is that it is impossible to create a dangling pointer if no
>> unchecked programming is used. (Unchecked_Deallocation, 
>> 'Unchecked_Access,
>> Unchecked_Conversion, Address_to_Access_Conversions, abuse of
>> Unchecked_Unions, etc.) That goes for all access types (not just 
>> anonymous
>> ones). The problem, of course, is that it is impractical to do much 
>> without
>> using one of those things. (I've only succeeded in using 'Access once in 
>> one
>> of my programs; in all other cases I had to use 'Unchecked_Access.)
>
> Anonymous access types seem to help quite a bit.  I use 'Access for
> access discriminants, creating proxies, to fake the in-out parameter
> mode for functions, and on locally defined callback functions.

Well, of course for "in out", just use that if you are using Ada 2012 -- no 
need to fake it.

The other uses of course will remain.

>> (Personally, I prefer to hide pointers as much as possible, as in
>> the container cursors, so that dangling pointer detection becomes
>> much more possible, and their creation becomes less likely.)
>
> And implicit deference could make them even safer to use.

Exactly. And more convinient, too.

I would like to see containers use to be as easy as using access types; if 
that is true, then there is little reason to use the less safe access types 
to create lists and trees (and maps and sets). There always will be cases 
not covered by containers or where performance needs are ultra-critical --  
but those should be the unusual cases. Ada 2012 definitely moves us closer 
to that goal.

                                       Randy.





      reply	other threads:[~2011-04-30 23:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-28 11:47 Ada 2012 : aliased parameters ? Yannick Duchêne (Hibou57)
2011-03-28 11:56 ` Dmitry A. Kazakov
2011-03-29  3:04   ` Randy Brukardt
2011-03-28 11:56 ` AdaMagica
2011-03-29 18:22   ` Florian Weimer
2011-03-29 18:34     ` Shark8
2011-03-29 19:35       ` Florian Weimer
2011-03-30  0:12     ` Randy Brukardt
2011-03-29  3:16 ` Randy Brukardt
2011-03-29  7:34   ` Maciej Sobczak
2011-03-30  0:09     ` Randy Brukardt
2011-03-30 19:44       ` Randy Brukardt
2011-04-23 18:47   ` Florian Weimer
2011-04-25  7:19     ` Randy Brukardt
2011-04-28 19:47       ` Florian Weimer
2011-04-28 23:54         ` Randy Brukardt
2011-04-30 18:32           ` Florian Weimer
2011-04-30 23:46             ` Randy Brukardt [this message]
replies disabled

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