From: "Jacob Sparre Andersen news" <randy@rrsoftware.com>
Subject: Re: Generic access type convention and aliasing
Date: Tue, 7 May 2013 16:03:17 -0500
Date: 2013-05-07T16:03:17-05:00 [thread overview]
Message-ID: <kmbq6m$mf7$1@loke.gir.dk> (raw)
In-Reply-To: op.wwp94yh5ule2fv@cardamome
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2591 bytes --]
"Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr> wrote in message
news:op.wwp94yh5ule2fv@cardamome...
...
> Access disciminants are uncopiable.
>
>If so, that's *very easily defeated*:
The issue isn't really whether they can be copied, but rather whether their
lifetime can be extended beyond that of the enclosing object. And the answer
to this latter question is no. (This allows the enclosing object to include
tracking for when the access exists, as in the containers with their
tampering checks.)
So while you can copy them into a dynamic accessibility context, this
doesn't change their lifetime. So your program doesn't work at runtime. This
can't be a purely static check simply because of the existence of access
parameters and stand-alone access objects (both of which have dynamic rather
than static accessibility checks).
> procedure Foo is
...
> S : Storages.Instance_Type := Storages.Create;
> A1 : Pool_Specific_Access := S.Element; -- Illegal.
because it fails a static accessibility check.
> A2 : access Storages.Element_Type := S.Element; -- However still
> legal.
I'm not certain about this (SAOAATs require the accessibility lifetime to
be at least as long as the object itself, and this isn't). But let's assume
this is legal for the sake of argument.
> A3 : General_Access := S.Element; -- And the same.
Yes, of course this is legal, but it also includes a dynamic
accessibility check which will fail for this example. (S.Element is much
shorter lives than type General_Access). So it will raise Program_Error. You
will not have accomplished copying with this code.
>Far from what limited access type would be.
Not really, because we have to allow some copying of limited access values
or you wouldn't be able to use them at all. At least for initialization (you
need to be able to initialize one limited access value with the result of a
function returning such a thing). You also may want to pass the value into a
subprogram for further processing (which is safe, as the subprogram has to
return before the access is destroyed). In cases like these, "limited" is
too much.
Moreover, the use of access parameters and SAOAATs should be avoided unless
you really need dynamic accessibility. It's just one of the many reasons
that these things are dangerous and probably never should have been added to
Ada in the first place. If you don't use the dangerous constructs (say by
using AdaControl to flag them), you won't have the problem you illustrate
here.
Randy.
next prev parent reply other threads:[~2013-05-07 21:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-06 0:20 Generic access type convention and aliasing Yannick Duchêne (Hibou57)
2013-05-06 5:55 ` Yannick Duchêne (Hibou57)
2013-05-07 0:56 ` Randy Brukardt
2013-05-07 6:02 ` Yannick Duchêne (Hibou57)
2013-05-07 6:42 ` Yannick Duchêne (Hibou57)
2013-05-07 17:34 ` AdaMagica
2013-05-07 19:08 ` Yannick Duchêne (Hibou57)
2013-05-07 21:03 ` Jacob Sparre Andersen news [this message]
2013-05-07 22:13 ` Yannick Duchêne (Hibou57)
2013-05-08 11:28 ` Yannick Duchêne (Hibou57)
2013-05-08 20:44 ` 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