comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam@spam.com>
Subject: Re: C array to ada record interface
Date: Thu, 15 Jul 2004 01:23:02 GMT
Date: 2004-07-15T01:23:02+00:00	[thread overview]
Message-ID: <W%kJc.3320$Qu5.3121@newsread2.news.pas.earthlink.net> (raw)
In-Reply-To: <404ee0af.0407141517.30cacac7@posting.google.com>

Francisco Javier Loma Daza wrote:

> struct
> {
>    int a,b,c:
>    int len;
>    struct b* arr;
> } A;
> 
> And I would love to interface in Ada with a record with a discriminant
> 
> type B_array(len: Positive) is record
>     arr: array of B(1..len);
> end record;
> 
> type A(len: Positive) is
>    a,b,c: Integer;
>    arr:   A(len);
> end record;

Assuming you meant

    Arr : B_Array (Len => Len);

this won't work. What you have from C is a pointer; the actual array may 
  not even be contiguous with the struct. You'll have to do something like

type B_Ptr is access all B;
pragma Convention (C, B_Ptr);

type A_Info is record
    A, B, C : Interfaces.C.Int;
    Len     : Interfaces.C.Int;
    Arr     : B_Ptr;
end record;
pragma Convention (C, A_Info);

You only use these types when talking directly to C. For the rest of 
your application, you use something like the record you presented, and 
have your operations that talk to C convert between the 2.

-- 
Jeff Carter
"This trial is a travesty. It's a travesty of a mockery of a
sham of a mockery of a travesty of two mockeries of a sham. ...
Do you realize there's not a single homosexual on that jury?"
Bananas
27




  parent reply	other threads:[~2004-07-15  1:23 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 [this message]
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
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