Re: Calling Ada from C
- From: "hannibal.holm@xxxxxxxxx" <hannibal.holm@xxxxxxxxx>
- Date: 27 Feb 2007 04:49:22 -0800
On Feb 23, 2:53 pm, Stephen Leake <stephen_le...@xxxxxxxxxxxxxxxx>
wrote:
"hannibal.h...@xxxxxxxxx" <hannibal.h...@xxxxxxxxx> 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?
.
- Follow-Ups:
- Re: Calling Ada from C
- From: Jeffrey R. Carter
- Re: Calling Ada from C
- From: Adam Beneschan
- Re: Calling Ada from C
- References:
- Calling Ada from C
- From: hannibal.holm@xxxxxxxxx
- Re: Calling Ada from C
- From: Stephen Leake
- Calling Ada from C
- Prev by Date: Re: Ada.Command_Line and wildcards
- Next by Date: Re: F-22 Raptor software problem
- Previous by thread: Re: Calling Ada from C
- Next by thread: Re: Calling Ada from C
- Index(es):
Relevant Pages
|