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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,9d63f462ee97dc01,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,CP1252 Path: g2news2.google.com!postnews.google.com!b9g2000yqm.googlegroups.com!not-for-mail From: =?ISO-8859-1?Q?Hibou57_=28Yannick_Duch=EAne=29?= Newsgroups: comp.lang.ada Subject: C interface using a record with discriminant and representation clauses Date: Tue, 30 Jun 2009 16:01:53 -0700 (PDT) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 77.198.58.72 Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1246402913 12329 127.0.0.1 (30 Jun 2009 23:01:53 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 30 Jun 2009 23:01:53 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b9g2000yqm.googlegroups.com; posting-host=77.198.58.72; posting-account=vrfdLAoAAAAauX_3XwyXEwXCWN3A1l8D User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; fr),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6773 Date: 2009-06-30T16:01:53-07:00 List-Id: Hello, I wonder about what to think about it, while I could not imagine a better solution : Say a C structure is to be interfaced with Ada. The structure has a "count" member and a variable length array, commonly defined in C as something like elements[1]. I.e. a C structure like typedef struct { int count; my_element_type elements[1]; } my_struct; I'm tempted to use something like type Element_Type is ; for Element_Type'Size use ; type Array_Type is array (Index_Type range <>) of aliased Element_Type; pragma Convention (C, Entity =3D> Array_Type); type Record_Type (Length : Index_Type) is record Elements : Array_Type (1..Length); end record; for Record_Type use record Length at 0 range 0 .. Something; -- Tell the Ada compiler where the C -- compiler has placed the =93 discriminant =94 end record; pragma Convention (C, Entity =3D> Record_Type); Though the trouble may be that it is not possible to specify the bits address of Elements, beceause it is not possible to have something like =93 Elements at 0 range .. * Length - 1; =94 What to think about it ? Is it portable through most compilers ? ** Is it trustable ? **