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-Thread: 103376,8f7d6c5172a1d41b X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news1.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Michael Erdmann Newsgroups: comp.lang.ada Subject: Re: How to get around "access type must not be outside generic unit" Date: Sun, 17 Dec 2006 15:28:25 +0100 Message-ID: References: <45853BDC.5000902@obry.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de 5wW/cfgddisL6izC0Kov5g+59RUzXyFMpjaP+7GcrfcIqog70fKDV+ X-Orig-Path: hal.boavista.snafu.de!news User-Agent: Thunderbird 1.5 (X11/20060317) In-Reply-To: <45853BDC.5000902@obry.net> Xref: g2news2.google.com comp.lang.ada:7930 Date: 2006-12-17T15:28:25+01:00 List-Id: Thanks; Solution 2 works, see below :-) Pascal Obry wrote: > Michael Erdmann a �crit : >> gnade@hal:~/test> gnatmake -c usage.adb >> gcc -c usage.adb >> usage.adb:16:28: access type must not be outside generic unit >> gnatmake: "usage.adb" compilation error >> >> What is the reason for this new compiler check and what can i do >> about it? > > Solution 1) Declare register using an anonymous access type : > > procedure Register > (Str : in String; A : access function return Boolean); > Actually this does not work; compiler complains the anonymous types are not allowed here. > Solution 2) Move access to generic spec > > with Base; use Base; > > generic > type Data_Type is private; > package Usage is > > function Install return Boolean ; > procedure Doit( X : in out Data_Type ); > > Install_Access : P_Access := Install'Access; > > end Usage; > This works. In order to make Install_Access invisible to the rest of the world i make it private. with Base; use Base; generic type Data_Type is private; package Usage is function Install return Boolean ; procedure Doit( X : in out Data_Type ); private Install_Access : constant Callback_Access := Install'Access; end Usage; But what is the gain of doing it like this. I don't see any gain in security..?! > ---- usage.adb > with Base; use Base; > > package body Usage is > > function Install return Boolean is > begin > return True; > end Install; > > procedure Doit( X : in out Data_Type ) is > begin > null; > end Doit; > > begin > Register ("Doit", Install_Access); > end Usage; > > package Base is > > type P_Access is access function return Boolean; > > procedure Register (Str : in String; A : P_Access); > > end Base; > > Pascal. >