comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic.brenta@insalien.org>
Subject: Re: Getting length of array from C
Date: Tue, 01 Feb 2005 21:07:08 +0100
Date: 2005-02-01T21:07:25+01:00	[thread overview]
Message-ID: <87lla8doyb.fsf@insalien.org> (raw)
In-Reply-To: 1107263868.447580.257310@z14g2000cwz.googlegroups.com

"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.



  parent reply	other threads:[~2005-02-01 20:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-01  4:16 Getting length of array from C Chuck
2005-02-01  5:26 ` Simon Wright
2005-02-01  7:25 ` Martin Krischik
2005-02-01 13:17   ` Chuck
2005-02-01 14:17     ` Martin Krischik
2005-02-01 20:07     ` Ludovic Brenta [this message]
2005-02-07  6:55       ` Dave Thompson
2005-02-02  0:15     ` Jeffrey Carter
2005-02-02  2:22     ` Steve
replies disabled

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