comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Ada 2012 : aliased parameters ?
Date: Mon, 25 Apr 2011 02:19:35 -0500
Date: 2011-04-25T02:19:35-05:00	[thread overview]
Message-ID: <ip37ae$n4q$1@munin.nbi.dk> (raw)
In-Reply-To: 87aafgerez.fsf@mid.deneb.enyo.de

"Florian Weimer" <fw@deneb.enyo.de> wrote in message 
news:87aafgerez.fsf@mid.deneb.enyo.de...
>* Randy Brukardt:
>
>> The motivating case is to make the containers better. Ada 2012 adds the
>> following to all of the containers:
>>
>>     function Reference (Container : aliased in out Vector; Position : in 
>> Cursor)
>>        return Reference_Type;
>>
>> where Reference_Type is defined as:
>>
>>     type Reference_Type (Element : not null access Element_Type) is 
>> private
>>        with
>>           Implicit_Dereference => Element;
>
> Is it necessary that Element is a discriminant?

Yes, because access discriminants have special accessibility rules which 
happen to have the right effect.

>  If the aliased business works with fields, you could write something like 
> this:
>
>  type String_Reference is record
>     Data : access String;
>  end record;

You can write this, but you lose all accessibility checking if you do. The 
accessibility of a normal component is that of the type, which is typically 
library level. OTOH, a discriminant in a returned object has the 
accessibility of the point of call; combined with the rules for aliased 
parameters, such a discriminant will always succeed (no runtime checks or 
overhead needed) and will always be safe (can't copy it into anything with a 
longer lifetime, which is essentially anything).

I'm no fan of accessibility checks, but in this case at least they don't get 
in the way beyond preventing operations that we don't want to allow in the 
first place.

>In any case, it seems to me that the definition of "master" in 7.6.1 needs 
>updating.

It did, but only for bugs. The access discriminant semantics is from Ada 95, 
although it was never defined properly (probably still isn't, although not 
for the lack to trying). We've just found a good use for the strange 
semantics.

                              Randy.







  reply	other threads:[~2011-04-25  7:19 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 [this message]
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
replies disabled

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