From: "Hovers" <hovers@dera.gov.uk>
Subject: Re: Question about interfacing C and Ada95
Date: 1999/11/09
Date: 1999-11-09T00:00:00+00:00 [thread overview]
Message-ID: <808la7$4b9$1@trog.dera.gov.uk> (raw)
In-Reply-To: 8076h5$d3c$1@nnrp1.deja.com
In followup would this be sort of correct.
It falls over however on the first text_io.put_line
Thanks for your help.
================================ C CODE ======================
/* standard includes */
#include <stdlib.h>
#include <stdio.h>
typedef struct
{
float val;
} INSTANCE;
void createObject ( void **inst, int *error_code )
{
*inst = malloc ( sizeof ( INSTANCE ) );
( ( INSTANCE * ) *inst )->val = 10.0f;
*error_code = 1;
}
void getFloat ( void **inst, float *val, int *error_code )
{
*val = ( ( INSTANCE * ) *inst )->val;
*error_code = 1;
}
================== ADA CODE =======================
with Text_IO;
with Interfaces.C;
with SYSTEM;
procedure get is
type Access_Int_Type is access Interfaces.C.Int;
type Access_C_Float_Type is access Interfaces.C.C_Float;
type Instance_Type is access SYSTEM.ADDRESS;
Error_Code : Access_Int_Type := NULL;
Instance : Instance_Type := NULL;
Val : Access_C_Float_Type := NULL;
procedure Create_Object
( Instance : in out Instance_Type;
Error_Code : in out Access_Int_Type );
pragma Import ( C, Create_Object, "createObject" );
procedure Get_Float
( Instance : in out Instance_Type;
Val : in out Access_C_Float_Type;
Error_Code : in out Access_Int_Type );
pragma Import ( C, Get_Float, "getFloat" );
begin -- get
Create_Object ( Instance, Error_Code );
Text_IO.Put_Line ( Interfaces.C.Int'image ( Error_Code.all ) );
Get_Float ( Instance, Val, Error_Code );
Text_IO.Put_Line ( Interfaces.C.Int'image ( Error_Code.all ) );
end get;
"Robert Dewar" <robert_dewar@my-deja.com> wrote in message
news:8076h5$d3c$1@nnrp1.deja.com...
> In article <806ud0$lu1$1@trog.dera.gov.uk>,
> "Hovers" <hovers@dera.gov.uk> wrote:
> > if I have a c routine that returns more than one value what is
> thge best way
> > to interface to Ada with it.
> >
> > e.g. int getX ( void **instance, int *float );
> >
> > we have recoded the c to this as Ada funcs do not allow more
> > than one return
>
> Both Ada and C allow exactly one value to be returned.
>
> Both Ada and C allow pointers to be passed by value, allowing
> the called subprogram (function or procedure in Ada) to modify
> the calling parameter.
>
> Ada in addition for procedures only, has a feature (out
> parameters) that is not allowed in C at all.
>
> But it does not seem there is any significant problem here!
>
> Yes, it would be nice if you could model pointer parameters in
> C with out parameters in functions in Ada, but you can't and
> you certainly don't need to. Just call the function as you
> would in C, passing a pointer if the parameter is of a pointer
> type.
>
> If necessary (but please ONLY if necessary) use aliased and
> 'Access to pass a pointer to a declared variable.
>
>
>
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
next prev parent reply other threads:[~1999-11-09 0:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-11-08 0:00 Question about interfacing C and Ada95 Hovers
1999-11-08 0:00 ` tmoran
1999-11-09 0:00 ` Robert Dewar
1999-11-08 0:00 ` Robert Dewar
1999-11-09 0:00 ` Hovers [this message]
1999-11-09 0:00 ` Matthew Heaney
1999-11-09 0:00 ` Ted Dennison
1999-11-12 0:00 ` Hovers
1999-11-12 0:00 ` Robert Dewar
1999-11-12 0:00 ` Ted Dennison
1999-11-13 0:00 ` Robert Dewar
1999-11-08 0:00 ` Matthew Heaney
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox