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,e9184f90d0749b32,start X-Google-Attributes: gid103376,public From: chris@ECE.Concordia.CA (Chris O'Regan) Subject: Using a procedure as a parameter (Gnat) Date: 1996/03/26 Message-ID: <4ja0da$442@newsflash.concordia.ca>#1/1 X-Deja-AN: 144394786 organization: ECE - Concordia University nntp-posting-user: chris newsgroups: comp.lang.ada Date: 1996-03-26T00:00:00+00:00 List-Id: I am writing a subprogram that accepts as one of its parameters the name of another subprogram. As described in "Rendezvous with Ada 95", I can achieve this by defining the parameter as an access type that points to a subprogram. As a test, I typed in an example from the book and successfully compiled it using gnat v3.03. This is the source: procedure Foo is Total: Integer; function P (I: in Integer) return Integer is begin return (I ** 2) + (5 * (I - 7)); end; type Polynomial is access function (N: in Integer) return Integer; function Sum_Of_Terms (Poly : in Polynomial; From, To: in Integer) return Integer is Sum: Integer := 0; begin for Term in From..To loop Sum := Sum + Poly (Term); end loop; return Sum; end Sum_Of_Terms; begin Total := Sum_Of_Terms (Poly => P'Access, From => 3, To => 8); end Foo; I then re-wrote the example such that the subprogram was part of the package and the subprogram being passed was defined in the main procedure. Unfortunately, when I try to compile the main procedure, it fails to build the executable with this error: $ gnatmake ack.adb gcc -c ack.adb ack.adb:11:35: subprogram must not be deeper than access type gnatmake: *** compilation failed. Below are the source files: ack.adb: ======== with Bar; use Bar; procedure Ack is Total: Integer; function P (I: in Integer) return Integer is begin return (I ** 2) + (5 * (I - 7)); end; begin Total := Sum_Of_Terms( Poly => P'Access, From => 3, To => 8 ); end Ack; bar.ads: ======== package Bar is type Polynomial is access function ( N: in Integer ) return Integer; function Sum_Of_Terms( Poly: in Polynomial; From, To: in Integer ) return Integer; end Bar; bar.adb: ======== package body Bar is function Sum_Of_Terms( Poly: in Polynomial; From, To: in Integer ) return Integer is Sum: Integer := 0; begin for Term in From..To loop Sum := Sum + Poly (Term); end loop; return Sum; end Sum_Of_Terms; end Bar; Can anyone tell me what this cryptic error message means and why this is not compiling? Please respond by e-mail. Many thanks in advance, -- ____________________________________________________________________ Chris O'Regan , UNIX Systems Administrator Department of Electrical and Computer Engineering Concordia University, Montreal, Canada http://www.ECE.Concordia.CA/~chris/addr.html