comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: C array to ada record interface
Date: Sun, 25 Jul 2004 19:28:40 GMT
Date: 2004-07-25T19:28:40+00:00	[thread overview]
Message-ID: <IRTMc.162301$IQ4.104037@attbi_s02> (raw)
In-Reply-To: 87iscdi6m5.fsf@insalien.org

> (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;



  parent reply	other threads:[~2004-07-25 19:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-14 23:17 C array to ada record interface Francisco Javier Loma Daza
2004-07-15  0:36 ` Brian May
2004-07-15  1:23 ` Jeffrey Carter
2004-07-22 18:02   ` Francisco Javier Loma Daza
2004-07-24 18:48     ` Ludovic Brenta
2004-07-25 17:26       ` Francisco Javier Loma Daza
2004-07-25 19:28       ` tmoran [this message]
2004-07-26 21:42         ` Ludovic Brenta
2004-07-27 21:04           ` tmoran
2004-07-27 22:15             ` Martin Dowie
2004-07-28  2:42             ` Robert I. Eachus
2004-07-29  5:56               ` tmoran
2004-07-29 19:58                 ` Robert I. Eachus
replies disabled

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