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: a07f3367d7,5afd69f1373c41cc X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,CP1252 Path: g2news2.google.com!postnews.google.com!t21g2000yqi.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Interfacing with C ; an ununsed fields dilemma Date: Thu, 2 Jul 2009 02:45:04 -0700 (PDT) Organization: http://groups.google.com Message-ID: <5a416858-4a52-412d-8051-6dadb5eadb2c@t21g2000yqi.googlegroups.com> References: NNTP-Posting-Host: 137.138.182.236 Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1246527913 12361 127.0.0.1 (2 Jul 2009 09:45:13 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 2 Jul 2009 09:45:13 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: t21g2000yqi.googlegroups.com; posting-host=137.138.182.236; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.11) Gecko/2009060214 Firefox/3.0.11,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6791 Date: 2009-07-02T02:45:04-07:00 List-Id: On 2 Lip, 08:20, Hibou57 (Yannick Duch=EAne) wrote: > Once again, a topic about interfacing with C structures. > > A lot of C structure are defined with so called =93 unused field > reserved for future use =94 (oftenly never used in any future). [...] I think that the most reasonable approach to interfacing with such APIs is to write a very thin "sanitizing" layer in C that will expose the interface shaped especially for easy interfacing from Ada. In other words, think about this complete structure: Ada application | | (calls) V Ada interfacing wrapper | | (interfaces to) V C interface wrapper | | (provides easy access to) V C messy-crappy-lib If you think that such a structure would be more work to do (there is additional C layer to write), then it is not. The comfort that you gain on the Ada side with clean functions that do not have to mess with the dodgy details of bit fields, alignment and whatnot, is certainly worth it. In some cases it is actually the only way to go, because in some C libraries the data structure layout can change from version to version and even though the proper layout is always defined in C header files, they are not *automatically* understood by Ada. You are not going to update your Ada wrapper every time, really. It is also the only way to interface with more elaborated C++ libraries. -- Maciej Sobczak * www.msobczak.com * www.inspirel.com Database Access Library for Ada: www.inspirel.com/soci-ada