comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: Interfacing with C ; an ununsed fields dilemma
Date: Thu, 2 Jul 2009 02:45:04 -0700 (PDT)
Date: 2009-07-02T02:45:04-07:00	[thread overview]
Message-ID: <5a416858-4a52-412d-8051-6dadb5eadb2c@t21g2000yqi.googlegroups.com> (raw)
In-Reply-To: faaa30f7-d69b-4c73-ae70-9b01d3804077@d32g2000yqh.googlegroups.com

On 2 Lip, 08:20, Hibou57 (Yannick Duchêne) <yannick_duch...@yahoo.fr>
wrote:

> Once again, a topic about interfacing with C structures.
>
> A lot of C structure are defined with so called “ unused field
> reserved for future use ” (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



  parent reply	other threads:[~2009-07-02  9:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-02  6:20 Interfacing with C ; an ununsed fields dilemma Hibou57 (Yannick Duchêne)
2009-07-02  9:25 ` Martin
2009-07-02 18:14   ` reserved fields; was " tmoran
2009-07-02  9:45 ` Maciej Sobczak [this message]
2009-07-02 12:01   ` Hibou57 (Yannick Duchêne)
2009-07-02 12:09     ` Georg Bauhaus
2009-07-02 13:21       ` Hibou57 (Yannick Duchêne)
2009-07-02 15:50         ` Georg Bauhaus
2009-07-02 14:52     ` Maciej Sobczak
2009-07-02 23:21       ` Hibou57 (Yannick Duchêne)
2009-07-03  7:21         ` Maciej Sobczak
2009-07-02  9:51 ` Georg Bauhaus
2009-07-02 10:16   ` Martin
2009-07-02 11:48     ` Hibou57 (Yannick Duchêne)
2009-07-02 15:55 ` Robert A Duff
2009-07-04  0:03   ` Randy Brukardt
2009-07-03  6:59 ` anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox