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,6a614d58fc5237e8 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!texta.sil.at!geiz-ist-geil.priv.at!news.iks-jena.de!not-for-mail From: Lutz Donnerhacke Newsgroups: comp.lang.ada Subject: Re: Interfacing to C: API with structures but without binary layout Date: Tue, 12 Jun 2007 20:19:27 +0000 (UTC) Organization: IKS GmbH Jena Message-ID: References: <1181678983.377288.225770@d30g2000prg.googlegroups.com> NNTP-Posting-Host: belenus.iks-jena.de X-Trace: branwen.iks-jena.de 1181679567 8137 2001:4bd8:0:666:248:54ff:fe12:ee3f (12 Jun 2007 20:19:27 GMT) X-Complaints-To: usenet@iks-jena.de NNTP-Posting-Date: Tue, 12 Jun 2007 20:19:27 +0000 (UTC) User-Agent: slrn/0.9.8.0 (Linux) Xref: g2news1.google.com comp.lang.ada:16173 Date: 2007-06-12T20:19:27+00:00 List-Id: * 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.