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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,9a3da26ec7b587c X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!noris.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Generic 'access-to-subprogram' formal Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <9e0a0ceb-7767-4d36-a29e-a51c23b8a0a6@m3g2000yqf.googlegroups.com> <86c18193-459f-410f-b7a7-aba62ca03095@k19g2000yqc.googlegroups.com> Date: Sat, 9 Jan 2010 19:52:38 +0100 Message-ID: <1p7zqgrrgydvs.14xsj4cicf826$.dlg@40tude.net> NNTP-Posting-Date: 09 Jan 2010 19:52:34 CET NNTP-Posting-Host: b778feb6.newsspool2.arcor-online.net X-Trace: DXC=m5N3G1nURN\cHPTNZh_e7QA9EHlD;3YcR4Fo<]lROoRQ8kFh?[\[L On Sat, 9 Jan 2010 10:08:20 -0800 (PST), xorque wrote: > On Jan 9, 5:03�pm, AdaMagica wrote: >> >> generic >> � type Some_Type is private; >> � type Acc_Proc �is access procedure (A: Some_Type); > > Thanks. > > I suppose it's not possible to be less specific? > > dlopen()-like functions might return a pointer to any type > of subprogram, so I'd want to do something like: > > generic > type Subprogram_Access_Type is access private; > > function Load_Subprogram (Name : in String) return > Subprogram_Access_Type; > > I don't see anything in the RM that might accommodate this. > > The Load_Subprogram doesn't need to know anything about > the type other than the fact that it's an access to something. > > I have a feeling I'm going to be unsafely converting a > System.Address... Sure, if you cannot say anything about the result. The only property of the result is to be something. The conversion is unsafe anyway, because the linker cannot prove the profile. You could do it like this: function Get_Address (External_Name : String) return Address is begin ... -- loading the external procedure from a DLL end Get_Address; Later on, for some procedure: procedure DB_Open (Name : char_array); for DB_Open'Address use Get_Address ("dbopen"); pragma Import (C, DB_Open); However, there is no much use in such wrappers, because for C bindings you have to convert some parameters and results. Make procedures functions, where C is unable to return an object on the stack. Wrap procedures into controlled types (e.g. data base connection handle). Drop return codes converting them to exceptions. And so on. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de