From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Subprogram Pointer in a Generic
Date: 17 Apr 2003 16:39:59 -0400
Date: 2003-04-17T16:39:59-04:00 [thread overview]
Message-ID: <wccwuhsg8o0.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 1ftiuys.1twhum2q9qa00N%claveman@grzorgenplatz.net
claveman@grzorgenplatz.net (Charles H. Sampson) writes:
> I'm using a procedure that takes a procedure pointer as an
> argument. It's pretty standard stuff:
>
> type Parameterless_Proc_Ptr is access procedure;
> procedure Register (The_Proc : in Parameterless_Proc_Ptr);
>
> My problem occurs when I want to call this procedure from within a
> generic package. I can't, because 3.10.2(32) says "If the subprogram
> denoted by P [the prefix of 'Access] is declared within a generic body,
> S [the access-to-subprogram type of the formal parameter] shall be
> declared within the generic body."
>
> Now that's no good for me at all, so I've kludged my way around it
> by taking the address of the actual argument procedure and changing it
> to a pointer using Unchecked_Conversion, a technique guaranteed to work
> for the current version of my current compiler on my current target
> machine.
>
> There are two questions. (1) What are they trying to prevent by
> this restriction?
First, you can't take 'Access of a nested procedure when the access type
is less nested (nested within procedures, I mean). That's because you
could then call the procedure after the containing procedure is done, so
the nested one no longer exists (and the variables visible to it no
longer exist).
If you do the 'Access in a generic, the compiler doesn't know (when
compiling the generic) whether the instance will be nested. The AARM says:
32.a Discussion: The part about generic bodies is worded in terms of the
denoted subprogram, not the denoted view; this implies that renaming
is invisible to this part of the rule. This rule is partly to
prevent contract model problems with respect to the accessibility
rules, and partly to ease shared-generic-body implementations, in
which a subprogram declared in an instance needs to have a different
calling convention from other subprograms with the same profile.
>... (2) Is there a more robust way of working around it?
The solution is easy: declare the procedure you're taking 'Access of in
the private part of the generic, rather than in the body. And don't
instantiate the generic in a nested place.
- Bob
next prev parent reply other threads:[~2003-04-17 20:39 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-04-17 1:53 Subprogram Pointer in a Generic Charles H. Sampson
2003-04-17 2:54 ` James S. Rogers
2003-04-17 3:15 ` Samuel Tardieu
2003-04-17 5:27 ` tmoran
2003-04-17 3:12 ` Samuel Tardieu
2003-04-17 4:17 ` tmoran
2003-04-17 20:24 ` Robert A Duff
2003-04-18 2:59 ` Charles H. Sampson
2003-04-22 16:34 ` Warren W. Gay VE3WWG
2003-04-22 21:17 ` Robert A Duff
2003-04-23 20:46 ` Warren W. Gay VE3WWG
2003-04-17 19:41 ` Matthew Heaney
2003-04-17 20:39 ` Robert A Duff [this message]
2003-04-17 23:14 ` 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