From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Interfacing to C: big structures
Date: Mon, 25 Feb 2008 17:26:00 -0600
Date: 2008-02-25T17:26:00-06:00 [thread overview]
Message-ID: <fpvkso$id2$1@jacob-sparre.dk> (raw)
In-Reply-To: c48dc7da-6f04-4f0f-9a8f-e0acc371ee3c@o10g2000hsf.googlegroups.com
"Maciej Sobczak" <see.my.homepage@gmail.com> 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.
next prev parent reply other threads:[~2008-02-25 23:26 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-25 21:17 Interfacing to C: big structures Maciej Sobczak
2008-02-25 23:26 ` Randy Brukardt [this message]
2008-02-25 23:26 ` Randy Brukardt
2008-02-27 13:23 ` Maciej Sobczak
2008-02-25 23:26 ` Randy Brukardt
2008-02-25 23:43 ` Robert A Duff
2008-02-26 13:53 ` Stephen Leake
2008-02-26 21:12 ` Randy Brukardt
2008-02-26 2:36 ` Steve
2008-02-26 12:00 ` Alex R. Mosteo
2008-02-26 14:05 ` Robert A Duff
2008-02-26 15:19 ` Alex R. Mosteo
2008-02-26 15:33 ` Robert A Duff
2008-02-26 16:21 ` Alex R. Mosteo
2008-02-27 1:28 ` Robert A Duff
2008-03-10 1:38 ` David Thompson
2008-02-26 17:35 ` Adam Beneschan
2008-02-26 19:47 ` Simon Wright
2008-02-26 21:14 ` Randy Brukardt
2008-02-27 1:40 ` Robert A Duff
2008-02-27 17:12 ` Adam Beneschan
2008-02-27 20:37 ` Simon Wright
2008-02-28 11:30 ` Alex R. Mosteo
2008-02-28 15:53 ` Robert A Duff
2008-02-29 10:45 ` Alex R. Mosteo
2008-02-27 1:37 ` Robert A Duff
2008-02-27 13:49 ` Maciej Sobczak
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox