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,35ee0472de38e833 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-12-11 21:54:12 PST Path: supernews.google.com!sn-xit-02!supernews.com!216.227.56.88.MISMATCH!telocity-west!TELOCITY!cyclone.bc.net!cyclone-sjo1.usenetserver.com!news-out.usenetserver.com!newshub2.rdc1.sfba.home.com!news.home.com!news1.frmt1.sfba.home.com.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: RE: Variable length raw-byte data References: X-Newsreader: Tom's custom newsreader Message-ID: <84jZ5.19011$M5.761837@news1.frmt1.sfba.home.com> Date: Tue, 12 Dec 2000 05:54:12 GMT NNTP-Posting-Host: 24.20.190.201 X-Complaints-To: abuse@home.net X-Trace: news1.frmt1.sfba.home.com 976600452 24.20.190.201 (Mon, 11 Dec 2000 21:54:12 PST) NNTP-Posting-Date: Mon, 11 Dec 2000 21:54:12 PST Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: supernews.google.com comp.lang.ada:2981 Date: 2000-12-12T05:54:12+00:00 List-Id: >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.