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=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.ams3.giganews.com!border1.nntp.ams2.giganews.com!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!goblin2!goblin3!goblin.stu.neva.ru!news.netfront.net!not-for-mail From: Tarek Ghaleb Newsgroups: comp.lang.ada Subject: Re: System.Address to Access to function/procedure conversion Date: Sun, 28 Jul 2013 19:05:44 +0000 (UTC) Organization: Netfront http://www.netfront.net/ Message-ID: References: <15i0rfwzpj7cy$.ob5l4ffr5iqa$.dlg@40tude.net> NNTP-Posting-Host: 77.247.181.164 X-Trace: adenine.netfront.net 1375038344 41820 77.247.181.164 (28 Jul 2013 19:05:44 GMT) X-Complaints-To: news@netfront.net NNTP-Posting-Date: Sun, 28 Jul 2013 19:05:44 +0000 (UTC) User-Agent: slrn/1.0.1 (Linux) X-Original-Bytes: 2982 Xref: number.nntp.dca.giganews.com comp.lang.ada:182740 Date: 2013-07-28T19:05:44+00:00 List-Id: On 2013-07-28, Dmitry A. Kazakov wrote: > If you pass anything to C you should better keep it under C convention, > even if you are certain that C does not touch it. You should pass an > access-to-procedure/function to C and get it back. The access type will > have pragma Convention (C, ... set. You don't need address here. E.g. I agree completely. Using C convention is the way to do it. But is it *possible* to call a function using its address? (even if not a such a great idea) But let me explain how this question came about: I've been experimenting with writing a thick binding for FLTK for a couple of days now, just exploring the idea (which deserves a thread by itself, since it would be interesting to get some feedback). Anyway, one thing I started working on was callbacks, If I use C convention the user of the binding will also have to declare his procedure using C convention. For example (simplified) procedure Cb_Button; pragma Convention (C, Cb_Button); -- This is required I guess and then later register the callback with Btn.Callback(Cb_Button'Access); But if I remove pragma Conversion (C, Cb_Button); I get ...: subprogram "Cb_Button" has wrong convention ...: does not match convention of access type But I don't want the user to worry about using pragma Convention for every defined callback procedure or think in terms of interfacing with C (or in FLTK's case C++). Ideally, Callback() is not the actual imported callback() but it takes Ada friendly parameters and does any type conversions needed then calls the imported callback() function. I thought maybe it works like above but without the convention line and then Callback() would send the Address instead of the Access to the actual callback(). But maybe there is a better way to do it. There are other issues of course, for example: callbacks do take parameters and some are void* but that would complicate my question for the time being. Tarek. -- For fools rush in where angels fear to tread. -- Alexander Pope --- news://freenews.netfront.net/ - complaints: news@netfront.net ---