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,c6b9934af04bce01 X-Google-Attributes: gid103376,public From: John English Subject: Re: A question to the "access-type lifetime rule" Date: 2000/04/04 Message-ID: <38E9E6A5.AC631EEA@bton.ac.uk>#1/1 X-Deja-AN: 606543772 Content-Transfer-Encoding: 7bit References: <38E89AB9.7D33E88C@hamilton.physik.uni-konstanz.de> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: news@bton.ac.uk X-Trace: saturn.bton.ac.uk 954853074 25667 193.62.183.204 (4 Apr 2000 12:57:54 GMT) Organization: University of Brighton Mime-Version: 1.0 NNTP-Posting-Date: 4 Apr 2000 12:57:54 GMT Newsgroups: comp.lang.ada Date: 2000-04-04T12:57:54+00:00 List-Id: Bernd Rinn wrote: > > Hi, > > I am new to Ada and I am looking for an elegant way to get around a > restriction posed by the "access-type lifetime rule" for > access-to-subprogram types. First of all: does anyone know, why the > access-type lifetime matters and not the access-variable lifetime? (This > should prevent dangling pointers as well, I guess.) > > I want to write an numerical integration function, that is defined in a > separate package as > > type Integrand_Type is access function ( X : Long_Float ) return > Long_Float; > function Integrate(Integrand : Integrand_Type; Lower_Bound, Upper_Bound > : Long_Float) return Long_Float; > > Now I would like to call this from a main procedure and pass an access > attribute of a nested function of the main procedure as `Integrand'. Is > there a way to reach this? (Unchecked_Access is not an allowed attribute > for subprograms and I do not want to generate a package of it's own for > the integrand function.) If you declare the package where Integrate is declared like this: generic package X is ... then in the same declaration section as the nested function you say this: package Inner_X is new X; and voila, you have smuggled the declarations from X into the inner scope (the access level of Inner_X being the level at which the instantiation occurs). ----------------------------------------------------------------- John English | mailto:je@brighton.ac.uk Senior Lecturer | http://www.it.bton.ac.uk/staff/je Dept. of Computing | ** NON-PROFIT CD FOR CS STUDENTS ** University of Brighton | -- see http://burks.bton.ac.uk -----------------------------------------------------------------