comp.lang.ada
 help / color / mirror / Atom feed
From: Lutz Donnerhacke <lutz@iks-jena.de>
Subject: Re: Interfacing to C: API with structures but without binary layout
Date: Tue, 12 Jun 2007 20:19:27 +0000 (UTC)
Date: 2007-06-12T20:19:27+00:00	[thread overview]
Message-ID: <slrnf6tvuf.u32.lutz@belenus.iks-jena.de> (raw)
In-Reply-To: 1181678983.377288.225770@d30g2000prg.googlegroups.com

* Maciej Sobczak wrote:
> Another problem with interfacing: consider a C function that expects
> some data structure that is defined in terms of C struct definition,
> but without clear binary layout.

Hard problem even in C. The binary layout of passed structures might differ
between different executables notably between kernel and application, if the
C-compiler options of both are different enough.

> Now, in order to call such a function we need access to the
> appropriate header file, where the actual structure definition is
> provided. But Ada doesn't understand C headers and pragma Import(C,
> connect) will not be enough.

I wrote a very thin binding to the Linux kernel (resulting in a inlined
INT 80 after all). If the API/ABI does not define the struture closely enough
to use representation clauses, an Ada record with layout Pragma(C) did
always the job.

> A straightforward solution is to create a thin wrapper (in C) for the
> given function that will expect parameters in well-defined form and
> layout and just forward them to the interesting system call. This
> wrapper will have to be compiled separately on each target system,
> picking the actual structure definition from the appropriate system
> header. Ada can then call the wrapper function.
>
> Is this THE solution?

It is the canonical way, yes. Given the majority of existing software, you
can collect the information directly and provide platform specific Ada
sources. This is causes by the platform specific API, which can't be
described portable by a higher level language.



  reply	other threads:[~2007-06-12 20:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-12 20:09 Interfacing to C: API with structures but without binary layout Maciej Sobczak
2007-06-12 20:19 ` Lutz Donnerhacke [this message]
2007-06-12 22:36 ` Jeffrey Creem
replies disabled

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