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,bc334b8912d9286c X-Google-Attributes: gid103376,public From: Tucker Taft Subject: Re: import a C function returning char * Date: 1999/02/03 Message-ID: <36B89E5D.DC082B5B@averstar.com>#1/1 X-Deja-AN: 440292175 Content-Transfer-Encoding: 7bit Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: To: Stephen Leake Content-Type: text/plain; charset=us-ascii Organization: AverStar (formerly Intermetrics) Burlington, MA USA Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-02-03T00:00:00+00:00 List-Id: Stephen Leake wrote: > > I need to import the C function: > > char *sbs_read_error (void); > > I'd like to use the facilities in Interfaces.C, but since there is no > char_ptr type, I'm not clear what the correct method is. LRM B.3 (63 > .. 75) talk about various parameter passing modes, but there's no > discussion of function results. > > Since all parameters of an array type are passed by pointers, I could > assume function results are also passed by pointer, and try: > > declare > > function Sbs_Read_Error return Interfaces.C.char_array; > pragma Import (C, Sbs_Read_Error, "sbs_read_error"); > > Result : String (1 .. 30); > Result_Last : Natural; > > begin > > Interfaces.C.To_Ada (Sbs_Read_Error, Result, Result_Last); > > Text_Io.Put_Line (Result (1 .. Result_Last)); > > end; > > Is this going to work (I'll get around to compiling this soon)? I'm > using GNAT 3.11p and ObjectAda 7.12 on Windows NT; what about other > Ada compilers? This should work on ObjectAda, I believe. > -- Stephen Leake -- -Tucker Taft stt@averstar.com http://www.averstar.com/~stt/ Technical Director, Distributed IT Solutions (www.averstar.com/tools) AverStar (formerly Intermetrics, Inc.) Burlington, MA USA