comp.lang.ada
 help / color / mirror / Atom feed
* Access to subprogram
@ 2002-05-07 12:47 Sebastian
  2002-05-07 13:01 ` David C. Hoos
  0 siblings, 1 reply; 5+ messages in thread
From: Sebastian @ 2002-05-07 12:47 UTC (permalink / raw)


What is the meaning of this
" subprogram must not be deeper than access type"






^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Access to subprogram
@ 2002-05-07 12:56 Grein, Christoph
  0 siblings, 0 replies; 5+ messages in thread
From: Grein, Christoph @ 2002-05-07 12:56 UTC (permalink / raw)


> 
> What is the meaning of this
> " subprogram must not be deeper than access type"

package Pak is

  type Access_P is access procedure;
  Global: Access_P;

end Pak;

with Pak;
procedure Proc is

  procedure Local is separate;
  LA: Pak.Access_P := Local'Access;

begin
  Global := LA;
end Proc;

Here Local has a deeper level than Access_P, i.e. a shorter lifetime. The 
aforementioned rule forbids such a use as LA, since Global will point to a 
non-existing item after Porc has finished.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Access to subprogram
  2002-05-07 12:47 Sebastian
@ 2002-05-07 13:01 ` David C. Hoos
  2002-05-07 16:16   ` Stephen Leake
  2002-05-08  6:03   ` Sebastian
  0 siblings, 2 replies; 5+ messages in thread
From: David C. Hoos @ 2002-05-07 13:01 UTC (permalink / raw)



----- Original Message ----- 
From: "Sebastian" <sebastian.madunic@avionics.saab.se>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Tuesday, May 07, 2002 7:47 AM
Subject: Access to subprogram


> What is the meaning of this
> " subprogram must not be deeper than access type"
It means exactly what it says.  You're trying to take the access
value of a subprogram that is nested more deeply than is the
place where the access type is declared.

To remedy this, you need to do one of two things, viz.:

   1.  Declare the subprogram at library level -- i.e., not in
        a package or nested within another subprogram

   2.  Use 'Unrestricted_Access instead of 'Access, if you're
        using GNAT, and if your are certain that the lifetime of
        the subprogram is at least as long as the lifetime of the
        access type.


    




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Access to subprogram
  2002-05-07 13:01 ` David C. Hoos
@ 2002-05-07 16:16   ` Stephen Leake
  2002-05-08  6:03   ` Sebastian
  1 sibling, 0 replies; 5+ messages in thread
From: Stephen Leake @ 2002-05-07 16:16 UTC (permalink / raw)


"David C. Hoos" <david.c.hoos.sr@ada95.com> writes:

> From: "Sebastian" <sebastian.madunic@avionics.saab.se>
> > What is the meaning of this
> > " subprogram must not be deeper than access type"
> It means exactly what it says.  You're trying to take the access
> value of a subprogram that is nested more deeply than is the
> place where the access type is declared.
> 
> To remedy this, you need to do one of two things, viz.:
> 
>    1.  Declare the subprogram at library level -- i.e., not in
>         a package or nested within another subprogram
> 
>    2.  Use 'Unrestricted_Access instead of 'Access, if you're
>         using GNAT, and if your are certain that the lifetime of
>         the subprogram is at least as long as the lifetime of the
>         access type.

Rule 2 is actually too restrictive. You can use Unrestricted_Access if
you are sure that the lifetime of the program is at least as long as
that of all copies of the access value. The compiler assumes copies of
the access value can last as long as the access type, but you don't
have to.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Access to subprogram
  2002-05-07 13:01 ` David C. Hoos
  2002-05-07 16:16   ` Stephen Leake
@ 2002-05-08  6:03   ` Sebastian
  1 sibling, 0 replies; 5+ messages in thread
From: Sebastian @ 2002-05-08  6:03 UTC (permalink / raw)


Wow,
It works!

Thanks


"David C. Hoos" <david.c.hoos.sr@ada95.com> wrote in message
news:mailman.1020776522.17239.comp.lang.ada@ada.eu.org...
>
> ----- Original Message -----
> From: "Sebastian" <sebastian.madunic@avionics.saab.se>
> Newsgroups: comp.lang.ada
> To: <comp.lang.ada@ada.eu.org>
> Sent: Tuesday, May 07, 2002 7:47 AM
> Subject: Access to subprogram
>
>
> > What is the meaning of this
> > " subprogram must not be deeper than access type"
> It means exactly what it says.  You're trying to take the access
> value of a subprogram that is nested more deeply than is the
> place where the access type is declared.
>
> To remedy this, you need to do one of two things, viz.:
>
>    1.  Declare the subprogram at library level -- i.e., not in
>         a package or nested within another subprogram
>
>    2.  Use 'Unrestricted_Access instead of 'Access, if you're
>         using GNAT, and if your are certain that the lifetime of
>         the subprogram is at least as long as the lifetime of the
>         access type.
>
>
>
>





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-05-08  6:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-07 12:56 Access to subprogram Grein, Christoph
  -- strict thread matches above, loose matches on Subject: below --
2002-05-07 12:47 Sebastian
2002-05-07 13:01 ` David C. Hoos
2002-05-07 16:16   ` Stephen Leake
2002-05-08  6:03   ` Sebastian

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