comp.lang.ada
 help / color / mirror / Atom feed
From: fjloma@andaluciajunta.es (Francisco Javier Loma Daza)
Subject: Re: C array to ada record interface
Date: 22 Jul 2004 11:02:39 -0700
Date: 2004-07-22T11:02:39-07:00	[thread overview]
Message-ID: <404ee0af.0407221002.1cfdc21e@posting.google.com> (raw)
In-Reply-To: W%kJc.3320$Qu5.3121@newsread2.news.pas.earthlink.net

Jeffrey Carter <spam@spam.com> wrote in message news:<W%kJc.3320$Qu5.3121@newsread2.news.pas.earthlink.net>...
> 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.


Thanks, I think you understood well

I would want to use some more ada like array, you suggest to implement
that with accesors functions ... I was just wondering if it can be
done, the Len + Arr part, to be set up as an Ada array ...



  reply	other threads:[~2004-07-22 18:02 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
2004-07-22 18:02   ` Francisco Javier Loma Daza [this message]
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