comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Ada 2012 : aliased parameters ?
Date: Mon, 28 Mar 2011 22:16:45 -0500
Date: 2011-03-28T22:16:45-05:00	[thread overview]
Message-ID: <imriv1$3ti$1@munin.nbi.dk> (raw)
In-Reply-To: op.vs1xo8puule2fv@index.ici

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2314 bytes --]

"Yannick Duch�ne (Hibou57)" <yannick_duchene@yahoo.fr> wrote in message 
news:op.vs1xo8puule2fv@index.ici...
...
>     Quote from Ada 2012:
>
>     Parameters can now be explicitly aliased, allowing parts of
>     function results to designate parameters and forcing
>     by-reference parameter passing.
>
>I'm not sure I've understood. What was wrong with access type parameters ?

Two things: (1) need to explicitly write 'Access at every call site, when 
all you are doing is passing a by-reference parameter; (2) anonymous access 
requires a run-time accessibility level; that means that passing the wrong 
thing (a local object, for instance) might cause Program_Error to be raised 
later. This is an unnecessary hazard for the sorts of uses envisioned for 
aliased parameters. Aliased parameters move the check to the call site, 
where it almost always will succeed (there is one case involving function 
calls inside of allocators where it might fail, and if it does it almost 
always will fail at compile-time).

> I don't see a reason why aliased parameters may be required (and don't 
> feel this can be clean). Well, why not in/out parameter for functions, as

Ada 2012 allows "in out" parameters on functions. The usual use of aliased 
parameters is on an "in out" parameter.

>things like test-and-set are common idioms, but I really can't figure why 
>this one in particular was required.

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;

The aspect "Implicit_Dereference" lets you omit "Element.all" from uses of 
this type, so the call:

    My_Vector.Reference (My_Cursor).Comp := 10;

is legal (presuming the element type has a component "Comp"). And another 
"feature" allows a form of user-defined indexing, so you actually can write:

   My_Vector (My_Cursor).Comp := 10;

which is a big improvement over using Update_Element (which requires writing 
a procedure to do an in-place element update).

                                     Randy.





  parent reply	other threads:[~2011-03-29  3:16 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 [this message]
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
replies disabled

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