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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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 Path: g2news2.google.com!news1.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!kanaga.switch.ch!switch.ch!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.straub-nv.de!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Ada to C interfacing with access on unconstrained array Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <2ec52d54-31f6-4289-9a9a-d947be65758c@o21g2000vbl.googlegroups.com> <1pe7su4hhh3ul.t10o4zs4n5i2.dlg@40tude.net> Date: Wed, 21 Oct 2009 14:09:51 +0200 Message-ID: <1lisu857l2qte$.1trga8b0qw0fq$.dlg@40tude.net> NNTP-Posting-Date: 21 Oct 2009 14:09:52 CEST NNTP-Posting-Host: 609a4d55.newsspool3.arcor-online.net X-Trace: DXC=oeXjlf6hHn9kUFX=Y?aLP;McF=Q^Z^V384Fo<]lROoR18kF7enW;^6ZC`4IXm65S@:3>?5GOdGVKXDE8 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:8769 Date: 2009-10-21T14:09:52+02:00 List-Id: On Wed, 21 Oct 2009 02:25:52 -0700 (PDT), dhenry wrote: > On 20 oct, 18:11, "Dmitry A. Kazakov" > wrote: >> BTW, why >> >> � �type Coco_Type is record >> � � � X : Integer; >> � � � Y : Integer; >> � � � Nuts : Nut_Array_Access; >> � �end record; >> >> and not >> >> � �type Coco_Type (Size : Natural) is record >> � � � X : Integer; >> � � � Y : Integer; >> � � � Nuts : Nut_Array_Type (1..Size); >> � �end record; > > Well, I quickly tested the discriminant version of Coco_Type with my > application needs, and indeed I could use a discriminant to replace > the access. So I may reconsider my Coco_Type definition. > > Would the discriminant version help me for my Ada->C interfacing? No. It could only if the types you use would have C convention of the parameters you are dealing with. The problem is not how Nut_Array_Type is constrained, but what are its elements. For example: type Nut_Type is record Diameter : int; Weight : int; Age : int; end record; pragma Convention (C, Nut_Type); type Nut_Type_Ptr is access all Nut_Type; pragma Convention (C, Nut_Type_Ptr); type Nut_Array_Type is array (Positive range <>) of aliased Nut_Type; pragma Convention (C, Nut_Array_Type); procedure Climb_C ( X : int; Y : int; Nuts : Nut_Type_Ptr; Len : unsigned ); pragma Export (C, Climb_C); This sort of Climb_C can be called from C. Inside it you can call Climb passing the array "as-is", provided Climb used the type Nut_Array_Type: procedure Climb (X, Y : int; Nuts : Nut_Array_Type); procedure Climb_C ( X : int; Y : int; Nuts : Nut_Type_Ptr; Len : unsigned ) is subtype Actual_Array_Type is Nut_Array_Type (1..Natural (Len)); Actual_Array : Actual_Array_Type; for Actual_Array'Address use Nuts.all'Address; begin Climb (X, Y, Actual_Array); -- Normally, this should not copy Actual_Array upon subtype -- conversion (from Actual_Array_Type to Nut_Array_Type) end Climb_C; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de