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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8522260ffbf09d84,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-03 08:58:46 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: taashlo@cyberdude.com (Tad Ashlock) Newsgroups: comp.lang.ada Subject: Problem With Self-Referential Access-to-Subprogram Type Date: 3 Nov 2003 08:58:45 -0800 Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 134.253.26.9 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1067878726 25776 127.0.0.1 (3 Nov 2003 16:58:46 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 3 Nov 2003 16:58:46 +0000 (UTC) Xref: archiver1.google.com comp.lang.ada:2000 Date: 2003-11-03T08:58:45-08:00 List-Id: (Background information: I'm an Ada newbie using GNAT 3.15p on Windows 2000.) In the demonstration code below, State1 compiles and works fine, but the declaration of State2 generates an error (premature use of "State2"). package Test is -- A little ADT: type Test_Type is tagged private; function Get_Dummy (Tester : Test_Type) return Integer; procedure Set_Dummy (Tester : in out Test_Type; Dummy : in Integer); -- An access-to-function type that works (but Tester is read-only): type State1; type State1 is access function (Tester : Test_Type'Class) return State1; -- An access-to-procedure type that doesn't work: type State2; type State2 is access procedure (Tester : in out Test_Type'Class; Resultant_State : out State2); -- premature use of "State2" right here ^ private type Test_Type is tagged record Dummy : Integer; end record; end Test; I started off by calling functions via variables of type State1. But then I needed to make changes to the Tester parameter within the functions (e.g. calling Set_Dummy). So I decided to change to calling procedures via variables of type State2. But this resulted in error messages (premature use of "State2"). Technically, I could still use an access-to-function type (State1) and just change the Tester parameter to be an access to Test_Type'Class *and* make all variables and constants of Test_Type aliased *and* pass them using the 'Access attribute *and* change certian packages to be generic *and* carefully instantiate them in the right scope to avoid the "non-local pointer cannot point to local object" errors. But that doesn't feel right. The subprograms being accessed *do* have side-effects and *should* be procedures rather than functions. Changing to the parameter to an access type to get around the "functions have input parameters only" rule seems like cheating. Besides, the changes listed above seem like alot of hassle for very little return. Effectively, I just want to change to returning the value via an "out" parameter rather than via a function result. Am I missing something obvious? Thanks for your help, Tad