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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,35ae3d13e899b684 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-29 22:04:15 PST Path: supernews.google.com!sn-xit-02!supernews.com!news.gv.tsc.tdk.com!news.iac.net!news-out.cwix.com!newsfeed.cwix.com!feed2.news.rcn.net!rcn!wn4feed!worldnet.att.net!135.173.83.71!wnfilter1!worldnet-localpost!bgtnsc06-news.ops.worldnet.att.net.POSTED!not-for-mail From: "David Thompson" Newsgroups: comp.lang.ada References: Subject: Re: Need help mapping a C struct to Ada X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Message-ID: Date: Fri, 30 Mar 2001 05:59:36 GMT NNTP-Posting-Host: 12.89.136.210 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc06-news.ops.worldnet.att.net 985931976 12.89.136.210 (Fri, 30 Mar 2001 05:59:36 GMT) NNTP-Posting-Date: Fri, 30 Mar 2001 05:59:36 GMT Organization: AT&T Worldnet Xref: supernews.google.com comp.lang.ada:6230 Date: 2001-03-30T05:59:36+00:00 List-Id: (null) 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