From: "Michael B." <michaelb@example.com>
Subject: Re: Access parameters and accessibility
Date: Wed, 17 Dec 2014 15:30:55 +0100
Date: 2014-12-17T15:30:55+01:00 [thread overview]
Message-ID: <m6s42s$pib$1@speranza.aioe.org> (raw)
In-Reply-To: 72048e0e-164a-4dce-8818-69454011a618@googlegroups.com
On 12/16/14 22:34, sbelmont700@gmail.com wrote:
> I have a copy of the paper around, if you are that into things, but
> it's certainly not a casual read, nor does it really appeal to anyone
> except for the phony-tough or crazy-brave.
I would be happy if you could send me a copy. My mail address is:
mb_public <at> safe-mail <dot> net
I hope it will not cause too much damage to my mental health ;-)
> procedure Example6 is
>
> type T is ...;
>
> procedure P1(XP1 : access T) is
> type A is access T;
> Ptr: A := null;
>
> procedure P2(XP2: access T) is
> begin
> Ptr := A(XP2);
> end P2;
>
> begin
> P2(XP1);
> end P1;
>
> X : aliased T;
>
> begin
> declare
> Y : aliased T:
> begin
> declare
> Z : aliased T;
> begin
> P1(X'Access);
> P1(Y'Access);
> P1(Z'Access); -- pass or fail?
> end;
> end;
> end Example6;
> In this example, note that all the objects X, Y and Z are all longer
> lived than type A, which conceptually only exists for the duration
> that P1 is executing, so each conversion should pass. But also note
> that the "depths" of the objects that P1 (and consequently, P2) is
> getting are becoming progressively "deeper" as each declarative block
> gets elaborated. The question then becomes what "depths" should the
> conversion in P2 be checking? If the normal block-nesting level was
> used (where X is 1, Y is 2, and Z is 3), then Z would become evaluated
> as "too deep", since A would be 2 and Z would be 3, and you would get
> an erroneous program error doing the conversion.
>
> So you can tweak things to say that in these special cases, you pass
> the *lower* of either the actual object depth or P1 itself. So, in
> this case, now Z will pass the dynamic check since instead of getting
> the depth of Z, P2 gets the depth of P1 (since 1<3). Now you can nest
> the declarative blocks a billion levels deep, and the proposed model
> still adheres to the LRM.
Ah, this is a nice example with a good explanation.
Thank you very much! Now I think I understand why this rule exists and
how it is working.
> Again, it's important to stress that this is just one special case of
> one special part of just one possible implementation of one
> special-case language feature from twenty years ago, and that none of
> this should weigh heavily on your mind when learning or using Ada.
Does that mean that a compiler writer is allowed to implement this rule,
but it is not strictly necessary?
I tried to compile and run your example. I replaced
"type T is ...;" by "type T is new Integer;"
and "type A is access T;" by "type A is access all T;"
to get it compiled (with Gnat 4.9 on Debian Jessie 8.0 amd64).
It runs but "P1(Z'Access);" raises Program_Error.
If I understand you correctly this is not a compiler bug and this
optional rule was just not implemented in Gnat, right?
Regards,
Michael
next prev parent reply other threads:[~2014-12-17 14:30 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-15 16:52 Access parameters and accessibility Michael B.
2014-12-15 17:54 ` Dmitry A. Kazakov
2014-12-15 18:48 ` Jeffrey Carter
2014-12-15 20:23 ` Michael B.
2014-12-15 21:02 ` Dmitry A. Kazakov
2014-12-16 1:10 ` sbelmont700
2014-12-16 13:57 ` Michael B.
2014-12-16 14:12 ` Georg Bauhaus
2014-12-16 21:34 ` sbelmont700
2014-12-17 14:30 ` Michael B. [this message]
2014-12-17 15:41 ` sbelmont700
2014-12-18 17:48 ` Michael B.
2014-12-17 16:03 ` Adam Beneschan
2014-12-18 16:07 ` Michael B.
2014-12-16 7:45 ` Randy Brukardt
2014-12-16 8:48 ` Stefan.Lucks
2014-12-16 20:47 ` Randy Brukardt
2014-12-16 21:24 ` Georg Bauhaus
2014-12-16 9:08 ` Natasha Kerensikova
2014-12-16 10:00 ` Dmitry A. Kazakov
2014-12-16 14:57 ` Robert A Duff
2014-12-16 19:46 ` Michael B.
2014-12-16 20:59 ` Randy Brukardt
2014-12-17 7:02 ` Natasha Kerensikova
2014-12-17 8:28 ` Dmitry A. Kazakov
2014-12-17 9:06 ` Natasha Kerensikova
2014-12-17 22:58 ` Randy Brukardt
2014-12-17 22:25 ` Randy Brukardt
2014-12-18 0:47 ` Shark8
2014-12-17 2:02 ` Adam Beneschan
2014-12-17 23:18 ` Randy Brukardt
2014-12-18 0:56 ` Robert A Duff
2014-12-18 1:17 ` Randy Brukardt
2014-12-18 5:29 ` Shark8
2014-12-18 23:12 ` Randy Brukardt
2014-12-18 8:27 ` Dmitry A. Kazakov
2014-12-18 21:20 ` Randy Brukardt
2014-12-19 12:16 ` Michael B.
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox