From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,782d14fd472db944 X-Google-Attributes: gid103376,public From: "Hovers" Subject: Re: Question about interfacing C and Ada95 Date: 1999/11/09 Message-ID: <808la7$4b9$1@trog.dera.gov.uk>#1/1 X-Deja-AN: 546350216 References: <806ud0$lu1$1@trog.dera.gov.uk> <8076h5$d3c$1@nnrp1.deja.com> Organization: Defence Evaluation & Research Agency X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.5600 Newsgroups: comp.lang.ada Date: 1999-11-09T00:00:00+00:00 List-Id: 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 #include 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" wrote in message news:8076h5$d3c$1@nnrp1.deja.com... > In article <806ud0$lu1$1@trog.dera.gov.uk>, > "Hovers" 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.