From: mockturtle <framefritti@gmail.com>
Subject: Re: Accessibility Levels and Library-Level Units
Date: Tue, 24 Sep 2013 12:06:06 -0700 (PDT)
Date: 2013-09-24T12:06:06-07:00 [thread overview]
Message-ID: <c6b3556d-8eea-49b5-b23f-ef411301adaa@googlegroups.com> (raw)
In-Reply-To: <58149dd9-990d-415c-a121-bc7a1a69473c@googlegroups.com>
I am not a language lawyer, so maybe someone will be able to confirm/contradict me.
I think that the problem is that Test is "local to" (defined inside) Accessibility_Level_Test. The problem is that you could have a "perverted" procedure Sub like this
package body Bad is
Old_Access : Proc_Type;
procedure Sub(X : Proc_Type) is
begin
Old_Access := X;
end Sub;
procedure Boom is
begin
Old_Access("Boom");
end Boom;
end Bad;
Now, if your code was legal you could call
Accessibility_Level_Test;
Bad.Boom;
and the latter would use the access to (non-existing) Test saved by Sub, causing... a boom.
From your post I understand that Accessibility_Level_Test; is the "main" program, but I am afraid that this does not count, but maybe a LL would be able to explain this better.
Hope this help
Riccardo
On Tuesday, September 24, 2013 8:36:43 PM UTC+2, Eryndlia Mavourneen wrote:
> I have a package that defines a single procedure access type:
>
>
>
> 1. package Accessibility_Level_Def is
>
> 2. pragma Pure;
>
> 3. type Proc_Type is access procedure (An_Str : String);
>
> 4. end Accessibility_Level_Def;
>
>
>
> I have a main program which references it (and another package):
>
>
>
> 1. with Ada.Text_IO; use Ada.Text_IO;
>
> 2. with Accessibility_Level_Def; use Accessibility_Level_Def;
>
> 3. with Accessibility_Level_Implementation; use Accessibility_Level_Implementation;
>
> 4. procedure Accessibility_Level_Test is
>
> 5. procedure Test (Text : String);
>
> 6. procedure Test (Text : String) is
>
> 7. begin
>
> 8. Put_Line ("in Test");
>
> 9. end Test;
>
> 10.
>
> 11. The_Proc : Proc_Type;
>
> 12. begin
>
> 13. The_Proc := Test'Access;
>
> 14. Sub (Proc => The_Proc);
>
> 15. end Accessibility_Level_Test;
>
>
>
> Gnat 2012 (on Ubuntu) gives the error on line 13:
>
>
>
> "Subprogram must not be deeper than access type."
>
>
>
> I thought I understood accessibility levels, at least, I understood the examples I have found. Yet, this example appears to not have the same issues:
>
>
>
> 1) All the units -- packages and procedure -- are at library level.
>
> 2) The procedure is statically defined and is not going to be
>
> deallocated until the program exits.
>
>
>
> This is very frustrating and would seem to preclude the definition of a procedural access type in a separate definitions package. The Implementation package (defining procedure Sub but not shown) compiles nicely, btw.
>
>
>
> Is this a problem with Gnat? If not, how can I do what I want to do? The attribute Unchecked_Access is not available for subprogram access types.
>
>
>
> -- Eryndlia (KK1T)
next prev parent reply other threads:[~2013-09-24 19:06 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-24 18:36 Accessibility Levels and Library-Level Units Eryndlia Mavourneen
2013-09-24 18:54 ` Eryndlia Mavourneen
2013-09-24 19:23 ` Adam Beneschan
2013-09-24 19:06 ` mockturtle [this message]
2013-09-25 7:46 ` Dmitry A. Kazakov
2013-09-24 19:13 ` mockturtle
2013-09-24 19:23 ` Eryndlia Mavourneen
2013-09-24 19:27 ` Adam Beneschan
2013-09-24 20:02 ` J-P. Rosen
2013-09-24 20:17 ` Eryndlia Mavourneen
2013-09-24 20:32 ` Adam Beneschan
2013-09-24 19:31 ` Jeffrey Carter
2013-09-24 19:43 ` Eryndlia Mavourneen
2013-09-24 19:59 ` Adam Beneschan
2013-09-24 20:50 ` Robert A Duff
2013-09-25 14:40 ` Eryndlia Mavourneen
2013-09-25 21:34 ` Robert A Duff
2013-09-26 12:46 ` Eryndlia Mavourneen
2013-09-29 21:36 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox