comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: RE: Variable length raw-byte data
Date: Tue, 12 Dec 2000 05:54:12 GMT
Date: 2000-12-12T05:54:12+00:00	[thread overview]
Message-ID: <84jZ5.19011$M5.761837@news1.frmt1.sfba.home.com> (raw)
In-Reply-To: B6A1A9B09E52D31183ED00A0C9E0888C469933@nctswashxchg.nctswash.navy.mil

>Or
>In your interface routine, receive the pointer as an
>address, and then unchecked convert it.
> ...
>  type Byte_Array is array (positive range <>) of Byte;
>  buffer_Address : System.Address;
> ...
>      subtype Constrained_Byte_Array is Byte_Array(1..length);
>      function To_Buffer_Pointer is
>        new Ada.Unchecked_Conversion(System.Address,Constrained_Byte_Array);
> ...
>Something like that.  (Constructive corrections only please!)
  Instead of trying to use Unchecked_Conversion to change an address
into an access type (I presume that was meant here), use
System.Address_To_Access_Conversions.  That should work.  But a
System.Address need not be the same size as an access type (consider
various Intel memory models), and even an access to an unconstrained
array (which will involve an actual 'range being stored somewhere) and
an access to a constrained array (where the compiler might keep the
range somewhere else) may be different, and different from a
System.Address.

>I'm trying to shim to a C library that returns some data as a length in
>bytes and a pointer to the first byte. The length is not known at compile
 type Data_Array is array(1 .. 10_000) of Byte; -- big enough constrained array
 type Data_Array_Ptr is access all Data_Array;
 P : aliased Data_Array_Ptr;
 N : aliased Natural;
 ...
 if C_Func(N'access, P'access) /= Failure then ...
 -- P.all(0 .. N) contains result

If Data_Array is not constrained, then a pointer to one, ie a
Data_Array_Ptr, must handle the range somewhere.  If it's a fat pointer,
it's unlikely C_Func will be so kind as to supply it correctly.  If it
points to a descriptor of some kind for the actual array, it's again
unlikely C_Func will return such a beast.



  reply	other threads:[~2000-12-12  5:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-12-12  3:30 Variable length raw-byte data Beard, Frank
2000-12-12  5:54 ` tmoran [this message]
  -- strict thread matches above, loose matches on Subject: below --
2000-12-13 20:39 Beard, Frank
2000-12-14 13:30 ` Robert Dewar
2000-12-13  2:56 Beard, Frank
2000-12-13 15:52 ` Robert Dewar
2000-12-13 18:23   ` Larry Kilgallen
2000-12-13 19:26     ` Robert Dewar
2000-12-12 21:11 Beard, Frank
2000-12-12 21:00 Beard, Frank
2000-12-13 15:48 ` David Botton
2000-12-13 15:51   ` Lutz Donnerhacke
2000-12-13 19:34     ` Robert Dewar
2000-12-14  8:54       ` Lutz Donnerhacke
2000-12-13 23:10   ` Jeff Carter
2000-12-11 19:38 Julian Morrison
2000-12-12  5:19 ` Jeff Carter
2000-12-13  0:50 ` Robert Dewar
2000-12-13  8:56   ` Tristan Gingold
replies disabled

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