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=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8ecbc35ea893182f X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!feeder.erje.net!nuzba.szn.dk!news.jacob-sparre.dk!pnx.dk!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Interfacing to C: big structures Date: Mon, 25 Feb 2008 17:26:00 -0600 Organization: Jacob's private Usenet server Message-ID: References: NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: jacob-sparre.dk 1203984089 18850 69.95.181.76 (26 Feb 2008 00:01:29 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 26 Feb 2008 00:01:29 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1914 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1914 Xref: g2news1.google.com comp.lang.ada:20070 Date: 2008-02-25T17:26:00-06:00 List-Id: "Maciej Sobczak" wrote in message news:c48dc7da-6f04-4f0f-9a8f-e0acc371ee3c@o10g2000hsf.googlegroups.com... > Consider the C API that contains some structure S and a couple of > functions that operate on the state that is stored in the Struct. A > typical usage in C might be: ... > How to interface to this from Ada? I see two options: > > 1. Write a simple wrapper that will create S on the heap and use the > pointer everywhere. This is easy, but imposes the use of dynamic > memory, which for some reasons I might want to avoid. > 2. Create an Ada array of basic storage units of "appropriate size" > and pass its address to the C functions. The advantage of this > solution is that it does not impose any particular memory management > scheme, but the disadvantage is that it is potentially non-portable > (how to get the "appropriate size"?). > > Would you suggest some other solution? Use the Annex B interfacing facilities. The basic idea is to write the C types in Ada, add the pragma Convention C to them, and let the Ada compiler handle the rest. Is there some reason this doesn't work in this case? Randy.