From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Is this actually possible?
Date: Wed, 11 Dec 2019 18:38:34 +0100
Date: 2019-12-11T18:38:34+01:00 [thread overview]
Message-ID: <qsr9is$ra4$1@gioia.aioe.org> (raw)
In-Reply-To: 36d45c82-2a6b-4c60-baeb-1a4aef5189c7@googlegroups.com
On 2019-12-11 17:43, Lucretia wrote:
> I was thinking about extensible records recently (not tagged types), and thought to try to export a tagged type to C, not C++. It compiles, but the results aren't quite right, so wondering if it's possible or not.
>
> The idea is to export an array of tagged types as a C array to either a function or a variable / struct element. i.e.
Ada objects of tagged types have varying size and keep tag inside. Both
make them utterly incompatible with C.
> type Storage_Array is array (Positive range <>) of Storage_Element with
> Convention => C;
This type cannot be used with C because an object of will have bounds
inside.
If you need an array compatible with C, it must a "flat" array:
type C_Storage_Array is array (size_t) of Storage_Element;
Naturally you will never declare such objects in your program. You will
get them from C or allocate raw memory and then having the address of
the first element do:
A : C_Storage_Array;
pragma Import (Ada, A);
for A'Address use The_Address_Of_A;
It is your responsibility not to index it outside the bounds. Just like
in C.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2019-12-11 17:38 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-11 16:43 Is this actually possible? Lucretia
2019-12-11 17:38 ` Dmitry A. Kazakov [this message]
2019-12-11 17:54 ` Lucretia
2019-12-11 19:55 ` Randy Brukardt
2019-12-11 19:58 ` Dmitry A. Kazakov
2019-12-11 21:12 ` Lucretia
2019-12-11 21:34 ` Dmitry A. Kazakov
2019-12-12 2:00 ` Randy Brukardt
2019-12-12 9:26 ` Niklas Holsti
2020-04-08 16:10 ` Alejandro R. Mosteo
2019-12-12 10:17 ` Lucretia
2019-12-12 14:32 ` Dmitry A. Kazakov
2019-12-12 15:14 ` Lucretia
2019-12-12 15:15 ` Lucretia
2019-12-12 18:24 ` Dmitry A. Kazakov
2019-12-12 18:30 ` Lucretia
2019-12-12 19:09 ` Dmitry A. Kazakov
2019-12-12 20:54 ` Lucretia
2019-12-12 21:12 ` Dmitry A. Kazakov
2019-12-13 11:11 ` Lucretia
2019-12-11 19:59 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox