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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8cca2e0315177d3b X-Google-Attributes: gid103376,public From: Tucker Taft Subject: Re: Instantiating a generic formal procedure with an access procedure value Date: 2000/01/03 Message-ID: <3870E3F1.906FDFF4@averstar.com>#1/1 X-Deja-AN: 567823898 Content-Transfer-Encoding: 7bit Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.burl.averstar.com References: <84guh6$emh$1@nnrp1.deja.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: AverStar (formerly Intermetrics) Burlington, MA USA Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-01-03T00:00:00+00:00 List-Id: Jeff Carter wrote: > > Here's something that I haven't been able to figure out from the ARM. > No doubt I haven't looked in the right place yet. > > Suppose I have a package that provides an unprotected structure > (normally this would be a generic package, but that's not important for > this example): > > package S_U is > type Handle is limited private; > > procedure Op (Item : in out Handle; Item : in Integer); I presume you mean ------------------->>> Element : in Integer <<< > > generic -- Iterate > with procedure Action > (Element : in out Integer; Continue : out Boolean); > procedure Iterate (Over : in out Handle); > private -- S_U > ... > end S_U; > > Suppose I now want to use this package to create a protected structure: > > with S_U; > package S is > type Action_Ptr is access procedure > (Element : in out Integer; Continue : out Boolean); > > protected type Handle is > procedure Op (Element : in Integer); > procedure Iterate (Action : in Action_Ptr); > private -- Handle > Data : S_U.Handle; > end Handle; > end S; > > package body S is > protected body Handle is > procedure Op (Element : in Integer) is > begin -- Op > S_U.Op (Item => Data, Element => Element); > end Op; > > procedure Iterate (Action : in Action_Ptr) is > procedure Local is new S_U.Iterate (Action => ???); > -- What do I use here? Action.all is the name of a subprogram. It happens to have convention "protected" but that is irrelevant to a generic formal subprogram, which should accept subprograms of any convention. > begin -- Iterate > Local (Over => Data); > end Iterate; > end Handle; > end S; > > Neither Action nor Action.all will compile here. As usual, without the actual source and the actual error message, it will be hard to determine where the real problem lies. But it may be a compiler bug... > ... The only thing I've > found that will compile is > > procedure Iterate (...) is > procedure Dummy (Element : in out Integer; Continue : out Boolean) is > begin -- Dummy > Action (Element => Element, Continue => Continue); > end Dummy; > > procedure Local is new S_U.Iterate (Action => Dummy); > begin -- Iterate > Local (Over => Data); > end Iterate; > > Hopefully there's a way to avoid this extra procedure call. Action.all is the correct thing to use as the actual for a generic formal subprogram. > -- > Jeff Carter -- -Tucker Taft stt@averstar.com http://www.averstar.com/~stt/ Technical Director, Distributed IT Solutions (www.averstar.com/tools) AverStar (formerly Intermetrics, Inc.) Burlington, MA USA