From: Adam Beneschan <adam@irvine.com>
Subject: Re: pragma Pure (Ada)
Date: Fri, 7 Oct 2011 18:37:53 -0700 (PDT)
Date: 2011-10-07T18:37:53-07:00 [thread overview]
Message-ID: <e75f7e2b-552b-4724-8c1a-a9face86d895@x25g2000prg.googlegroups.com> (raw)
In-Reply-To: op.v2nho0dcule2fv@index.ici
On Sep 30, 7:11 pm, Yannick Duchêne (Hibou57)
<yannick_duch...@yahoo.fr> wrote:
> Le Sat, 01 Oct 2011 03:50:36 +0200, Yannick Duchêne (Hibou57)
> <yannick_duch...@yahoo.fr> a écrit:
>
> > In “A Brief Introduction to Ada 2012” (a great paper from John Barnes) ->
> >http://www2.adacore.com/wp-content/uploads/2006/03/Ada2012_Rational_I...
>
> On page 13, there's something I don't feel to understand
>
> > Programmers have always moaned about the need for many
> > explicit conversions in Ada. Accordingly, implicit
> > conversions from anonymous access types to named access
> > types are now permitted provided the explicit conversion is
> > legal. The idea is that the need for an explicit conversion
> > with access types should only arise if the conversion could
> > fail. A curious consequence of this change is that a
> > preference rule is needed for the equality of anonymous
> > access types.
>
> “a preference rule is needed for the equality of anonymous access types” ?
> What does that mean ?
If you have two objects of an anonymous access type that point to the
same type, in Ada 2005 you can test them for equality:
X : access My_Record;
Y : access My_Record;
if X = Y then ...
This calls a function "=" that is defined in the language and takes
"universal access types" as parameters.
If you define a named access type:
type My_Record_Acc is access My_Record;
this defines an implicit "=" operator:
function "=" (Left, Right : My_Record_Acc) return Boolean ...
[and you can override it with your own operator if you really want
to]. In Ada 2005, this didn't pose a problem. But in Ada 2012, if an
anonymous access type (access My_Record) could be implicitly converted
to a named access type (My_Record_Acc), then in this:
if X = Y then ...
the compiler couldn't tell whether "=" means the function on
"universal access", or the function on My_Record_Acc (since X and Y
can now be implicitly converted to My_Record_Acc). This is ambiguous,
and ambiguous function calls are normally an error, but making it an
error would make some legal Ada 2005 programs illegal in Ada 2012. So
a special rule had to be added to make the language *prefer* the
"universal access" equality function over any other function.
Hope this helps,
-- Adam
next prev parent reply other threads:[~2011-10-08 1:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-01 1:50 pragma Pure (Ada) Yannick Duchêne (Hibou57)
2011-10-01 2:11 ` Yannick Duchêne (Hibou57)
2011-10-08 1:37 ` Adam Beneschan [this message]
2011-10-08 22:54 ` Yannick Duchêne (Hibou57)
2011-10-09 6:34 ` Niklas Holsti
2011-10-10 15:06 ` Adam Beneschan
2011-10-01 2:28 ` Yannick Duchêne (Hibou57)
2011-10-08 1:08 ` Randy Brukardt
2011-10-08 23:00 ` Yannick Duchêne (Hibou57)
2011-10-01 3:09 ` Adam Beneschan
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox