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: a07f3367d7,f0256820d7b60c30 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder.news-service.com!de-l.enfer-du-nord.net!gegeweb.org!aioe.org!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Ada to C interfacing with access on unconstrained array Date: Tue, 20 Oct 2009 18:40:37 +0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: <2ec52d54-31f6-4289-9a9a-d947be65758c@o21g2000vbl.googlegroups.com> NNTP-Posting-Host: +ERTOT2Y9KJRZ8n+NpAZGA.user.aioe.org X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.0 X-Newsreader: Tom's custom newsreader Cancel-Lock: sha1:EmJd+YlCN9TwidRxQvJpNnW7kqg= Xref: g2news2.google.com comp.lang.ada:8756 Date: 2009-10-20T18:40:37+00:00 List-Id: > 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