From: "David Thompson" <david.thompson1@worldnet.att.net>
Subject: Re: Need help mapping a C struct to Ada
Date: Fri, 30 Mar 2001 05:59:36 GMT
Date: 2001-03-30T05:59:36+00:00 [thread overview]
Message-ID: <chVw6.1060$RF1.88816@bgtnsc06-news.ops.worldnet.att.net> (raw)
In-Reply-To: WH7u6.40$Je5.495@newsfeed.slurp.net
(null) <cts@kampong.aedinc.net> wrote :
> I'm trying to call some C functions from my Ada program. The C function
> prototype and data types are basically
...
> typedef struct {
> int num_elements;
> /*typedef to struct blah*/ the_elements[0];
> } element_table;
...
> My question is basically about the element_table structure. In C
> this means basically that element_table.the_elements doesn't have
> a fixed size. It is up to the programmer to figure out how much
> memory is needed for the desired number of elements and manual
> allocate the memory.
>
Only in GNU C, the language "not entirely unlike" C
compiled by the gcc C compiler by default, not in
standard C and not in (most?) other C compilers.
The 1989/90 standard requires the array bound to be
(fixed and) strictly positive. Since C does not require
bounds checking, and implementations rarely do it,
it *almost* always works to declare T foo [1],
malloc(sizeof(S)+ (N-1)*sizeof(T)), and use 0..N-1,
although this is ugly(er). Since this actually works
on reasonable implementations, the new 1999
standard makes it official but with a new, distinct
syntax, called "flexible array member":
typedef struct { ... T foo []; /* no bound at all */ } S;
ptr = malloc(sizeof(S) + N * sizeof(T));
--
- David.Thompson 1 now at worldnet.att.net
prev parent reply other threads:[~2001-03-30 5:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-03-21 19:56 Need help mapping a C struct to Ada (null)
2001-03-21 21:25 ` tmoran
2001-03-22 20:53 ` tmoran
2001-03-21 22:21 ` Jeffrey Carter
2001-03-21 23:12 ` Florian Weimer
2001-03-30 5:59 ` David Thompson [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