comp.lang.ada
 help / color / mirror / Atom feed
From: "hannibal.holm@gmail.com" <hannibal.holm@gmail.com>
Subject: Re: Calling Ada from C
Date: 27 Feb 2007 04:49:22 -0800
Date: 2007-02-27T04:49:22-08:00	[thread overview]
Message-ID: <1172580562.037493.251070@a75g2000cwd.googlegroups.com> (raw)
In-Reply-To: <uwt29t1yc.fsf@stephe-leake.org>

On Feb 23, 2:53 pm, Stephen Leake <stephen_le...@stephe-leake.org>
wrote:
> "hannibal.h...@gmail.com" <hannibal.h...@gmail.com> writes:
> > I have a slight problem trying to call an Ada function from a C
> > function. I need to pass in an unconstrained array to the Ada
> > function. The problem is how I specify the size.
>
> Since the concept "unconstrained array" doesn't exist in C, this can't
> possibly be a precise description of what you are doing.
>
> Can you give more context, and an example of the code? Especially the
> C declarations of the data structure you are passing to Ada.
>
> --
> -- Stephe

The data structure in C is just a pointer to a block of data to be
sent over a network link. This need to be converted to a byte array
defined as:

Byte_Size   : constant := 8;

type Byte is range 0 .. 2**Byte_Size - 1;
for Byte'Size use Byte_Size;

type Byte_Array is array (Natural range <>) of Byte;
pragma Pack (Byte_Array);

As said, I am not extremly familiar with Ada and come from a C-
background, so I have a few problems trying to figure out what the ada
runtime and type system actually does. I tried something like

-- This proc is exported as with C-conventions
procedure Some_Ada_Proc(Msg : in Byte_Array;
                        Len : in Natural) is
  Msg_Constr : Byte_Array := Msg(0 .. Length - 1);
begin
...
end Some_Ada_Proc;

This is called with:

char foo[] = {0xde, 0xad, 0xbe, 0xef};
some_ada_proc(foo, sizeof(foo)); // sizeof static array = 4

But that result in a crash which I assume is due to how Ada treats
arrays passed as arguments.

I would be very greatful for any help, and an explanation on what is
actually going on in the Ada runtime system, e.g. descriptions on how
the Ada ABI works in this case.

Preferably I would like to do a toll free conversion from the C-
pointer to the Ada array, is this possible?




  reply	other threads:[~2007-02-27 12:49 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-22 15:46 Calling Ada from C hannibal.holm
2007-02-22 16:17 ` Ludovic Brenta
2007-02-22 17:28 ` Adam Beneschan
2007-02-22 20:40 ` Aurele
2007-02-23 13:53 ` Stephen Leake
2007-02-27 12:49   ` hannibal.holm [this message]
2007-02-27 18:03     ` Adam Beneschan
2007-02-28  2:54     ` Jeffrey R. Carter
  -- strict thread matches above, loose matches on Subject: below --
2000-08-25  0:00 Maxwelton
1996-10-29  0:00 How is an ADA compiler done? Robert Dewar
1996-11-08  0:00 ` calling ADA from C EDSTAM Mikael
1996-11-14  0:00   ` Robert Dewar
1995-03-22 13:26 Calling Ada " Roger L Costello
1995-03-22 13:58 ` David Paton
1995-03-23 17:22 ` Theodore Dennison
1995-03-24 17:14   ` Larry Kilgallen, LJK Software
1995-03-26 11:53     ` Robert Dewar
1995-03-27 14:47       ` Theodore Dennison
1995-03-28  0:00         ` Cyrille Comar
1995-03-28  0:00         ` Robert Dewar
1995-03-29  2:47         ` Larry Kilgallen, LJK Software
1995-03-29  0:00           ` Theodore Dennison
1995-04-04  0:00             ` Robert Dewar
1995-03-27 19:48     ` Robert I. Eachus
1995-03-29  0:00       ` Larry Kilgallen, LJK Software
1991-02-23 16:01 calling " David B Lightstone
1988-10-16  0:23 calling ada from c Maureen Cragg
1988-10-17 17:21 ` Maureen Cragg
replies disabled

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