comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: Interfacing to C without dynamic memory
Date: Sun, 16 Nov 2008 13:31:14 -0800 (PST)
Date: 2008-11-16T13:31:14-08:00	[thread overview]
Message-ID: <088082af-1fa9-4636-a7e2-39731aa9a6be@k36g2000pri.googlegroups.com> (raw)
In-Reply-To: 87bpwhurxl.fsf@willow.rfc1149.net

On 15 Lis, 12:52, Samuel Tardieu <s...@rfc1149.net> wrote:

> Note that you can also do it at run time, even if it costs a few more
> cycles to allocate the object, by taking advantage of C ability to
> resolve "sizeof" into a static value at compile time. This obliviates
> the cross-compilation issues.

> const size_t T_size = sizeof(struct T);

>    T_Size : constant Interfaces.C.size_t;
>    pragma Import (C, T_Size, "T_size");

Neat. This possibility was not obvious to me.

>    type Opaque_T is new Interfaces.C.char_array (1 .. T_Size);
>    for Opaque_T'Alignment use 8;

Of course, I can similarly extract the magic 8 constant from the C
file (sizeof(long long) or such).

Two more questions:

1. Any technical difference between System.Storage_Array and
Interfaces.C.char_array? Considering that the target module is C,
using the latter is more logical, but apart from "name affinity" is
there anything that can make a difference in practice?

2. Now the array has run-time size instead of compile-time size (as
you mentioned yourself). Is there any difference, especially in terms
of memory management? Are such arrays guaranteed to be allocated on
the stack?

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com

Database Access Library for Ada: www.inspirel.com/soci-ada



      reply	other threads:[~2008-11-16 21:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-14 13:58 Interfacing to C without dynamic memory Maciej Sobczak
2008-11-14 20:35 ` Damien Carbonne
2008-11-15  1:12   ` Randy Brukardt
2008-11-14 23:13 ` Robert A Duff
2008-11-15 11:52   ` Samuel Tardieu
2008-11-16 21:31     ` Maciej Sobczak [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox