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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,73975695cdfcb86f X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.74.201 with SMTP id w9mr9276309pbv.0.1333454577709; Tue, 03 Apr 2012 05:02:57 -0700 (PDT) Path: r9ni13607pbh.0!nntp.google.com!news2.google.com!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Natasha Kerensikova Newsgroups: comp.lang.ada Subject: Re: Dispatching callback handed over to C Date: Tue, 3 Apr 2012 12:02:57 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <6fb83c74-b2a4-4ae8-9c89-d755b737198f@v22g2000vby.googlegroups.com> Mime-Version: 1.0 Injection-Date: Tue, 3 Apr 2012 12:02:57 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="Mda950WjNwNLAFOE7yJXQw"; logging-data="9176"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+SoiC2JX/PT20xiZlLq7or" User-Agent: slrn/0.9.9p1 (FreeBSD) Cancel-Lock: sha1:y67tseDyeqlCFNTyTzQ0PpsCYBQ= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: 2012-04-03T12:02:57+00:00 List-Id: On 2012-04-03, Maciej Sobczak wrote: > On 3 Kwi, 09:19, Natasha Kerensikova wrote: > >> The problem I'm facing currently is binding to a very common idiom for >> callback in C. > > [...] > > I had to solve this poblem in the context of the YAMI4 poject and I > managed to get the essential parts of the solution here: > > http://inspirel.com/articles/Polymorphic_Callbacks_Ada_Cpp.html Thanks a lot for the solution. It turns out this is almost what my tentative solution looked like, the only step I missed was to use System.Address to carry the data part, instead of some access type. But still, I can't help but think there is one needless subprogram call in that solution. With a way to obtain the address of the actual subprogram the dispatching call would dispatch to, the address could be handed over to C code so that it can call it directly. > The callback, as seen by Ada, is polymorphic (the user sees it as a > dipatching call). The solution does not involve any compiler-specific > magic any more than what could be expected, so should be quite > portable. Actually it uses the assumption that System.Address and void* have the same representation. I wonder how reliable the assumption is. Thanks for your insights, Natasha