comp.lang.ada
 help / color / mirror / Atom feed
From: "chris.danx" <chris.danx@ntlworld.com>
Subject: Re: Import a type from C
Date: Thu, 07 Nov 2002 19:00:27 +0000
Date: 2002-11-07T19:00:27+00:00	[thread overview]
Message-ID: <qMyy9.202$fX5.1042@news13-win.server.ntlworld.com> (raw)
In-Reply-To: <wmey9.336376$nc1.2504303@telenews.teleline.es>

Francisco Santoyo wrote:

 > Hi
 >
 > I have to use a type struct, which is defined in a C library. Anybody
 > know,
 > how can I import that type from C to Ada?
 >
 > Thanks.


As far as I'm aware you can't import a "type", but you can declare an
equivalent type and import variables of that type into Ada.  i.e. you
can't import the type X, only variables of type X.

struct myStruct {
    int x;
    int y;
    char *str;
};

would go to an Ada record

type myStruct is record
     x : integer;
     y : integer;
     str : blah -- haven't done this in a while.
end record;


The details are a little sketchy as I've been programming in Java for
two, maybe three months now (my knowlege of Ada is evaporating :( ), but
structs in C rougly correspond to records in Ada, C strings to Char_Ptr,
etc.  Of course, some of this depends on the compilers involved too, so
there's some variation.

What I would be inclined to do in the case of Strings would be to
convert C strings to proper Ada Strings, if I was going to use them in
Ada code and no more in C code (if you need to send them back, you have
to consider a tradeoff between the convienance of Ada strings and the
conversion between the two forms - which costs time).

The lovelace tutorial has some text on interfacing with C, which maybe
worth a look (it's a much better description than my pitiful attempt, so
you *should* read it to unconfuse yourself after reading my post :)  I
have a habit of doing stuff like that).  There's a link to it from
www.adapower.com iirc.


hth,
Danx
-- 
for personal replies change spamoff to chris




  parent reply	other threads:[~2002-11-07 19:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-06 19:48 Import a type from C Francisco Santoyo
2002-11-06 20:06 ` Frank J. Lhota
2002-11-06 23:10   ` Stephen Leake
2003-01-08 20:46     ` Rupert Pigott
2003-01-10  3:48       ` Eric G. Miller
2003-01-14  4:47       ` David Thompson
2002-11-07  7:16 ` Victor Porton
2002-11-07 13:47   ` Stephen Leake
2002-11-07 16:03   ` Frank J. Lhota
2002-11-07 16:20     ` Robert A Duff
2002-11-08 14:51       ` Stephen Leake
2002-11-07 19:00 ` chris.danx [this message]
2002-11-08  4:02 ` Victor Porton
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox