comp.lang.ada
 help / color / mirror / Atom feed
* Questions: interfacing to C
@ 2001-01-02  3:34 Julian Morrison
  2001-01-02  4:19 ` James Rogers
  2001-01-02  4:32 ` tmoran
  0 siblings, 2 replies; 6+ messages in thread
From: Julian Morrison @ 2001-01-02  3:34 UTC (permalink / raw)


Two questons, I can't see how the ARM resolves them.

First, I have in C:

   typedef struct foo {int a} FOO;
   typedef struct bar {FOO *b} BAR;

To shim to this from Ada, should I do:

   with Interfaces.C; use Interfaces.C;
   type FOO is record
      a : int;
   end record;
   pragma Convention (C, FOO);

   type FOO_Access is acess all FOO;
   pragma Convention (C, FOO_Access);

   type BAR is record
      b : FOO_Access;
   end record;
   pragma Convention(C, BAR);

Or will it not convert the access type - and i'd have to use
System.Address?

Next question, similarly I have in C:

   FOO* get_foo(void);

Can I shim to it as:

   function get_foo () return FOO_Access;
   pragma Import (C, get_foo);

or is it returning a System.Address?



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Questions: interfacing to C
  2001-01-02  3:34 Questions: interfacing to C Julian Morrison
@ 2001-01-02  4:19 ` James Rogers
  2001-01-02  4:54   ` Robert Dewar
  2001-01-02  4:56   ` Julian Morrison
  2001-01-02  4:32 ` tmoran
  1 sibling, 2 replies; 6+ messages in thread
From: James Rogers @ 2001-01-02  4:19 UTC (permalink / raw)


Your two questions seem to be summarized by: "How do I bind to a C
pointer?"

The answer is to use the package Interfaces.C.Pointers. This
package is described in section B.3.2 of the Ada Reference Manual.

Jim Rogers
Colorado Springs, Colorado USA



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Questions: interfacing to C
  2001-01-02  3:34 Questions: interfacing to C Julian Morrison
  2001-01-02  4:19 ` James Rogers
@ 2001-01-02  4:32 ` tmoran
  1 sibling, 0 replies; 6+ messages in thread
From: tmoran @ 2001-01-02  4:32 UTC (permalink / raw)


>Or will it not convert the access type - and i'd have to use
>System.Address?
>...
>or is it returning a System.Address?

There is a standard package System.Address_To_Access_Conversions.  There
would be no need of such a package if System.Address and Access types
were the same thing, so they must not be the same thing.

Interfaces.C.char_array is defined with "aliased" char.  "Aliased" has
nothing to do with System.Address, and everything to do with Access types.

LRM B.3(68) says
"An Ada 'access' T parameter ... is passed as a t* argument to a C
function, where t is the C type corresponding to the Ada type T."

Conclusion: The interface to C uses Access types, not System.Address.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Questions: interfacing to C
  2001-01-02  4:19 ` James Rogers
@ 2001-01-02  4:54   ` Robert Dewar
  2001-01-02  5:15     ` Julian Morrison
  2001-01-02  4:56   ` Julian Morrison
  1 sibling, 1 reply; 6+ messages in thread
From: Robert Dewar @ 2001-01-02  4:54 UTC (permalink / raw)


In article <3A515730.D2106823@worldnet.att.net>,
  James Rogers <jimmaureenrogers@worldnet.att.net> wrote:
> Your two questions seem to be summarized by: "How do I bind
to a C
> pointer?"
>
> The answer is to use the package Interfaces.C.Pointers. This
> package is described in section B.3.2 of the Ada Reference
Manual.


I really don't see why Interfaces.C.Pointers is relevant here.
Everything that is needed here can likely be found in Annex B.

Part of the trouble is that we do not have enough information
in the question, what does "shim" mean? One does not interface
directly to types, but typically through procedure calls, so
what we really need here is the full set of declarations.

Note that convention C_Pass_By_Copy is also relevant in this
discussion.,


Sent via Deja.com
http://www.deja.com/



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Questions: interfacing to C
  2001-01-02  4:19 ` James Rogers
  2001-01-02  4:54   ` Robert Dewar
@ 2001-01-02  4:56   ` Julian Morrison
  1 sibling, 0 replies; 6+ messages in thread
From: Julian Morrison @ 2001-01-02  4:56 UTC (permalink / raw)


"James Rogers" <jimmaureenrogers@worldnet.att.net> wrote:

> Your two questions seem to be summarized by: "How do I bind to a C
> pointer?"
> 
> The answer is to use the package Interfaces.C.Pointers. This package is
> described in section B.3.2 of the Ada Reference Manual.

I know the "pragma Import" converts some of the stuff (record to struct*)
but not if it converts returned pointers.

I also don't know if "pragma Convention (C, FOO)" allows access elements
within FOO to map straight onto equivalent pointers in the C struct
version.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Questions: interfacing to C
  2001-01-02  4:54   ` Robert Dewar
@ 2001-01-02  5:15     ` Julian Morrison
  0 siblings, 0 replies; 6+ messages in thread
From: Julian Morrison @ 2001-01-02  5:15 UTC (permalink / raw)


"Robert Dewar" <robert_dewar@my-deja.com> wrote:

> I really don't see why Interfaces.C.Pointers is relevant here.
> Everything that is needed here can likely be found in Annex B.
> 
> Part of the trouble is that we do not have enough information in the
> question, what does "shim" mean? One does not interface directly to
> types, but typically through procedure calls, so what we really need
> here is the full set of declarations.

I'm trying to "pragma Import" some C functions (a subset of OpenSSL's
crypto stuff, to be exact) and I have to build Ada equivalents of the
structs it requires and sometimes returns, so I can pass them around and
poke about inside (eg: to set up a RSA key struct from a received binary
public-key). I'm trying to figure the limits of what the language will do
for me as a freebie - as versus what I have to manually convert.
 
> Note that convention C_Pass_By_Copy is also relevant in this
> discussion.,

Where in the ARM is that one defined? I can't find the dratted thing.

PS, to you and anyone else who's responded, thanks :-)



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-01-02  5:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-01-02  3:34 Questions: interfacing to C Julian Morrison
2001-01-02  4:19 ` James Rogers
2001-01-02  4:54   ` Robert Dewar
2001-01-02  5:15     ` Julian Morrison
2001-01-02  4:56   ` Julian Morrison
2001-01-02  4:32 ` tmoran

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