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,73975695cdfcb86f X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.205.119.5 with SMTP id fs5mr1192950bkc.7.1333484456449; Tue, 03 Apr 2012 13:20:56 -0700 (PDT) MIME-Version: 1.0 Path: h15ni82318bkw.0!nntp.google.com!news1.google.com!goblin1!goblin2!goblin.stu.neva.ru!newsfeed.x-privat.org!news.jacob-sparre.dk!munin.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Dispatching callback handed over to C Date: Tue, 3 Apr 2012 15:20:47 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <6fb83c74-b2a4-4ae8-9c89-d755b737198f@v22g2000vby.googlegroups.com> <85d1ad51-c02b-44fa-87b6-02aa1d8ba1b2@x17g2000vba.googlegroups.com> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1333484453 25131 69.95.181.76 (3 Apr 2012 20:20:53 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 3 Apr 2012 20:20:53 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Date: 2012-04-03T15:20:47-05:00 List-Id: "Maciej Sobczak" wrote in message news:85d1ad51-c02b-44fa-87b6-02aa1d8ba1b2@x17g2000vba.googlegroups.com... > On 3 Kwi, 14:02, Natasha Kerensikova wrote: ... >> Actually it uses the assumption that System.Address and void* have the >> same representation. >> >> I wonder how reliable the assumption is. > > Whenever Ada and C (or C++) components are linked together, a set of > "friendly" compilers is needed, so that basic binary compatibility can > be guaranted - otherwise nothing is going to work at all, not even > Interfaces.C.int. :-) > This assumption is pretty safe. I disagree. It doesn't work in the current Janus/Ada compiler, for instance. The basic idea is that System.Address ought to be able to access any memory on the target that might have hardware located at it. Thus, that address might need to include segments or equivalent information along with the "address" itself. Matching the C compiler is irrelevant; we have access types and convention C for that purpose (and you can't match both of two possibly different requirements). Indeed, using System.Address for any purpose other than interfacing directly to hardware is Ada 83 thinking, in my view. (Not everyone agrees with this view.) Using System.Address loses type-safety, and prevents the compiler optimizer for working at all (it has to assume the worst about any object in your program, unless it is willing to completely trash your program). The whole idea of the void pointer is so anti-Ada that it is best to get rid of it as early as you can. (There is no such thing as "untyped data" in Ada, and, as Dmitry likes to point out, not in real life, either. There is only data for which the type is not known at compile-time, and that sort of data is a problem - best to avoid it.) In Claw, we tried to avoid void by simply defining the interfaces for the types we cared about. For instance, if we needed to read an array of stream elements, we'd define the API using that type (rather than void). In other cases, we defined a void type (as access to something) and used Unchecked_Conversions as needed to make it crystal-clear this is wildly unsafe. Obviously, you have to do something to interface to mindless APIs, but you have to hide them as quickly as possible. [That said, it is possible to go too far for your target. For instance, Windows can't use segments at all, so having them in System.Address is more likely to cause problems than fixes. The fact that our Windows compiler still has segments is actually a bug -- it supposedly was changed years ago -- it's in the change logs -- but somehow it disappeared from the actual definitions. Will get changed someday.] Randy.