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-Thread: 103376,91fb0c338516ed9 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.multikabel.nl!news.tudelft.nl!tudelft.nl!txtfeed1.tudelft.nl!transit0.news.tiscali.nl!tiscali!transit1.news.tiscali.nl!dreader2.news.tiscali.nl!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Getting length of array from C References: <1107231381.627097.52490@c13g2000cwb.googlegroups.com> <1107244808.d76a000ed3c64143f06cacb757120823@teranews> <1107263868.447580.257310@z14g2000cwz.googlegroups.com> From: Ludovic Brenta User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.3 (gnu/linux) Date: Tue, 01 Feb 2005 21:07:08 +0100 Message-ID: <87lla8doyb.fsf@insalien.org> Cancel-Lock: sha1:s5gRHU5/8wufvXTC4jZ9WJnZ4ow= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Tiscali bv NNTP-Posting-Date: 01 Feb 2005 21:07:25 CET NNTP-Posting-Host: 83.134.239.244 X-Trace: 1107288445 dreader2.news.tiscali.nl 44096 83.134.239.244:32796 X-Complaints-To: abuse@tiscali.nl Xref: g2news1.google.com comp.lang.ada:8121 Date: 2005-02-01T21:07:25+01:00 List-Id: "Chuck" writes: > Here's the deal. I currently have some Ada code. Quite a bit of it. > The originators of the code had done some C interfacing with the Ada > code. So, I have some procedures like the following: > > procedure Write_Array( my_array : in My_Array_Type ); > pragma Import( C, Write_Array, "c_write_array" ); > > The C function prototype from the header file I was given is: > void c_write_array( void *array ); > > In the C code is there anyway I can get the length of the incoming > array? So, is Ada actually passing in a structure or an array? > Hope this clears things up. > > Chuck No length information is passed to, or expected by the C function. The "designers" (if they call themselves that) of this old code don't want you to be bothered with array lengths :) Because of the pragma Import, there is no dope vector either; the C function just gets a void* pointing at the first element in the array. This reminds me of the C library's null-terminated strings. Of course, all the functions in the C library that fail to use a length parameter are deprecated (e.g. strdup is deprecated in favour of strndup). You should look for a design document that explains where the array ends; there may be a terminating element at the end of the array, or perhaps the array has a "well-known size" somewhere. If My_Array_Type is constrained, you're in luck because you'll know the size at compile time. -- Ludovic Brenta.