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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fcbc5bb7c18362e0,start X-Google-Attributes: gid103376,public From: JSharer-No_Spam_@psu.edu (Jack W. Sharer) Subject: HELP: Interfaces.C... Date: 2000/04/06 Message-ID: <8cipco$prq@r02n01.cac.psu.edu>#1/1 X-Deja-AN: 607686778 Organization: Penn State University, Center for Academic Computing Reply-To: JSharer-No_Spam_@psu.edu (Jack W. Sharer) Newsgroups: comp.lang.ada Date: 2000-04-06T00:00:00+00:00 List-Id: This note is a request for help with the Ada package Interfaces.C and its children. I'm interfacing to MathWorks' Matlab compute engine. MathWorks provides this interface as a "C" interface consisting of a compiled library and C header (".h") files. See under "Engine Routines" for a directory of this library. I've been successful in accessing the compute engine from Ada using the "Interfaces.C" package along with its children. The following code shows where I'm at using gnat Ada on a Sun: ----------------- Begin Code Segment --------------------- with System; with Interfaces.C.Strings; procedure Test is type Engine is new System.Address; procedure EngOutputBuffer ( Engine_Identifier: in Engine; Output_Buffer: out Interfaces.C.Char_Array; Buffer_Size: in Interfaces.C.Int ); pragma Import (C, EngOutputBuffer, "engOutputBuffer"); -- int engOutputBuffer(Engine *ep, char *p, int n); -- ep Engine pointer. -- p Pointer to character buffer of length n. -- n Length of buffer p. -- engOutputBuffer defines a character buffer for -- engEvalString to return any output that ordinarily -- appears on the screen. -- See -- From the ".h" file: -- typedef struct engine Engine; Ep: Engine; Matlab_Output: Interfaces.C.Char_Array(1..50000); begin -- ... EngOutputBuffer ( Ep, Matlab_Output, Interfaces.C.Int ( Matlab_Output'Length ) ); -- ... end Test; ------------------ End Code Segment ---------------------- While this code works, the form of the first and second arguments appear to go against the spirit of the Interfaces.C... packages. >From reading _Ada_as_a_Second_Language_, it appears that the second argument should be of type Interfaces.C.Strings.chars_ptr So following the information on page 986, I tried this: ------------------ Begin Code Segment -------------------- with Interfaces.C.Strings; use Interfaces.C.Strings; procedure Test_Access is procedure EngOutputBuffer ( OutputBuffer: in Chars_Ptr ); pragma Import (C, EngOutputBuffer, "engOutputBuffer"); Matlab_Output: aliased Interfaces.C.Char_Array(1..50000); begin EngOutputBuffer (To_Chars_Ptr(Matlab_Output'Access)); end Test_Access; ------------------- End Code Segment --------------------- A compilation failed with these messages: Warning: aliased object has explicit bounds Warning: declare with explicit initialization Warning: for use with unconstrained access Object subtype must statically match designated subtype Could you help me get into the Interfaces.C... spirit? Thanks,