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,d9e66bfe9beb10b9 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!wn14feed!worldnet.att.net!attbi_s02.POSTED!53ab2750!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: C array to ada record interface References: <87iscdi6m5.fsf@insalien.org> X-Newsreader: Tom's custom newsreader Message-ID: NNTP-Posting-Host: 24.6.132.82 X-Complaints-To: abuse@comcast.net X-Trace: attbi_s02 1090783720 24.6.132.82 (Sun, 25 Jul 2004 19:28:40 GMT) NNTP-Posting-Date: Sun, 25 Jul 2004 19:28:40 GMT Organization: Comcast Online Date: Sun, 25 Jul 2004 19:28:40 GMT Xref: g2news1.google.com comp.lang.ada:2380 Date: 2004-07-25T19:28:40+00:00 List-Id: > (PS. I have not tried to compile my example code, so there may be > errors in it) Could you post a complete, running, example please? I must have missed something. Here is my interpretation of such a thing, but, though it compiles on two out of three Ada compilers I tried, it generates (different) junk results on both. (The third compiler objects to the Unchecked_Conversion instantiation.) with ada.text_io, Ada.Unchecked_Conversion, interfaces.c; procedure testuc2 is type B is new integer; type B_Array is array(Interfaces.c.int range <>) of aliased B; type B_Ptr is access all B; pragma Convention (C, B_Ptr); function To_Ada_Array (Arr : in B_Ptr; Len : in Interfaces.C.int) return B_Array is subtype Array_With_Known_Length is B_Array (1 .. Len); function To_Ada is new Ada.Unchecked_Conversion (Source => B_Ptr, Target => Array_With_Known_Length); begin return To_Ada (Arr); end To_Ada_Array; procedure show(ba : in b_array) is begin ada.text_io.put_line("ba(3)="); ada.text_io.put_line(b'image(ba(3))); end show; x : b_array(1 .. 5) := (others=>17); begin show(to_ada_array(arr=>x(1)'access, len=>5)); end testuc2;