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,8ecbc35ea893182f X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!out02b.usenetserver.com!news.usenetserver.com!in04.usenetserver.com!news.usenetserver.com!in03.usenetserver.com!news.usenetserver.com!pc02.usenetserver.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Interfacing to C: big structures References: From: Stephen Leake Date: Tue, 26 Feb 2008 08:53:14 -0500 Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/22.1 (windows-nt) Cancel-Lock: sha1:gIu/DDaxoqWr6lO+MZ1HCIEzT1s= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: ec6cb47c41796e05e48ed32637 Xref: g2news1.google.com comp.lang.ada:20088 Date: 2008-02-26T08:53:14-05:00 List-Id: Robert A Duff writes: > Maciej Sobczak writes: > >> 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: > > Something like: > > type S is record ... end record; > pragma Convention (C, S); > > X : aliased S; > init (X'Access); -- or possibly 'Unchecked_Access > foo (X'Access); -- or ... Why not: procedure Init (X : in out S); procedure Foo (X : in out S); begin init (X); foo (X); end; -- -- Stephe