comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: Ada to C interfacing with access on unconstrained array
Date: Tue, 20 Oct 2009 18:40:37 +0000 (UTC)
Date: 2009-10-20T18:40:37+00:00	[thread overview]
Message-ID: <hbl074$deo$1@aioe.org> (raw)
In-Reply-To: 2ec52d54-31f6-4289-9a9a-d947be65758c@o21g2000vbl.googlegroups.com

>  type Nut_Array_Type is array (Positive range <>) of Nut_Type;
  C has no concept of an unconstrained array - only pointers to the
start of a length-less array.  The usual way to handle this is to
declare the Ada array constrained, but with a "sufficiently large"
constraint.  You can pass (a pointer to) such an array between C
and Ada.  You lose bounds checking on the Ada side, but you can
fudge that by renaming the actual slice.
So how about:

   type Nut_Array_Type is array (Positive range <>) of Nut_Type;
   subtype C_Nut_Array_Type is Nut_Array_Type(Positive);
   type C_Nut_Array_Access is access C_Nut_Array_Type;

   type Coco_Type is
      record
         X    : Integer;
         Y    : Integer;
         Nuts : C_Nut_Array_Access;
      end record;

   -- This is the procedure I want to be executed from C
   procedure Climb (Coco : in Coco_Type);
   ...
package body Foo is

   procedure Climb (Coco : in Coco_Type) is
     Coco_Nuts : renames Coco.Nuts.all(1 .. actual_length);
   begin



  parent reply	other threads:[~2009-10-20 18:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-20 13:07 Ada to C interfacing with access on unconstrained array dhenry
2009-10-20 16:11 ` Dmitry A. Kazakov
2009-10-21  9:25   ` dhenry
2009-10-21 12:09     ` Dmitry A. Kazakov
2009-10-21 12:14       ` Dmitry A. Kazakov
2009-10-20 16:24 ` Adam Beneschan
2009-10-20 18:40 ` tmoran [this message]
2009-10-21  3:29   ` John B. Matthews
2009-10-21  9:29     ` dhenry
2009-10-21 14:16       ` John B. Matthews
replies disabled

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