From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,72113392dc4997bd X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-04-17 13:39:59 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!newsfeed.cs.wisc.edu!144.212.100.101.MISMATCH!newsfeed!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Subprogram Pointer in a Generic Date: 17 Apr 2003 16:39:59 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1ftiuys.1twhum2q9qa00N%claveman@grzorgenplatz.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1050611999 8186 199.172.62.241 (17 Apr 2003 20:39:59 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 17 Apr 2003 20:39:59 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:36250 Date: 2003-04-17T16:39:59-04:00 List-Id: 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