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,fc95c1889fbed9e5 X-Google-Attributes: gid103376,public From: dewar@cs.nyu.edu (Robert Dewar) Subject: Re: C Interface question Date: 1996/07/09 Message-ID: #1/1 X-Deja-AN: 167549607 references: organization: Courant Institute of Mathematical Sciences newsgroups: comp.lang.ada Date: 1996-07-09T00:00:00+00:00 List-Id: Jerry asks int *function(int value, int *result); the function is called with a value and both the returned pointer and the result pointer contain data. So how do I interface to this ? If I use a procedure I lose the returned value and if I use a procedure I lose the result value. There are two obvious answers. You can pass an access to integer value as the second parameter, defining an access type. Or, if the pointer will never be null, then you can use a parameter that is access integer on the Ada side. Of course I could write a interface function in C, but then I might as well drop Ada althogether and write the whole package in C... :-( Seems a bit extreme ... but anyway, there is a trivially easy way to interface as above. Note that indeed passing an access type by value is in any case closest to the C semantics, which does not have call by reference. Note that in general the issue of passing out and in-out parameters to externally interfaced functions can be a bit irritating. For some reason people would not go along with the suggestion of allowing out and in out parameters on functions, even with the concession of restricting it to imported subporgrams. Dec has a pragma Import_Valued_Procedure that allows a function in the external world to be treated as a procedure with an initial out parameter that is the returned value on the Ada side. Using this pragma, we would have a third way of interfacing: procedure C_Function (Return_Val : out int; Value : int; Result : in out int); pragma Import (C, C_Function); pragma Import_Valued_Procedure (Internal => C_Function, External => "function", Mechanism => (value, value, reference)); This pragma (and all other DEC Ada pragmas and attributes) will be fully implemented in the next version of GNAT (some of them only make sense on VMS, but many of them, like the above example, are generally useful).