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,8ecbc35ea893182f,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!o10g2000hsf.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Interfacing to C: big structures Date: Mon, 25 Feb 2008 13:17:45 -0800 (PST) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 85.3.70.85 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1203974266 18192 127.0.0.1 (25 Feb 2008 21:17:46 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 25 Feb 2008 21:17:46 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: o10g2000hsf.googlegroups.com; posting-host=85.3.70.85; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:20062 Date: 2008-02-25T13:17:45-08:00 List-Id: Hi, 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: struct S s; init(&s); foo(&s); bar(&s); baz(&s); Above, s is created with automatic storage duration. 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? -- Maciej Sobczak * www.msobczak.com * www.inspirel.com