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: 103376,6a614d58fc5237e8,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!d30g2000prg.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Interfacing to C: API with structures but without binary layout Date: Tue, 12 Jun 2007 13:09:43 -0700 Organization: http://groups.google.com Message-ID: <1181678983.377288.225770@d30g2000prg.googlegroups.com> NNTP-Posting-Host: 85.3.208.3 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1181678984 9926 127.0.0.1 (12 Jun 2007 20:09:44 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 12 Jun 2007 20:09:44 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: d30g2000prg.googlegroups.com; posting-host=85.3.208.3; posting-account=Ch8E9Q0AAAA7lJxCsphg7hBNIsMsP4AE Xref: g2news1.google.com comp.lang.ada:16171 Date: 2007-06-12T13:09:43-07:00 List-Id: 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. A motivating example might be the connect(2) system call, which expects the sockaddr address structure. The only thing we know (by the standard) about this structure is that it contains *at least* some given fields. Depending on the actual system, however, it might contain some more fields for implementation-defined reasons, or they might be in different order, etc. 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. 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? -- Maciej Sobczak http://www.msobczak.com/