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.5 required=5.0 tests=BAYES_00,INVALID_MSGID, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,ef6c792702c0ff46 X-Google-Attributes: gid103376,public From: Simon Wright Subject: Re: ada to c interfaces and CHARS_PTR Date: 2000/03/11 Message-ID: #1/1 X-Deja-AN: 596401702 X-NNTP-Posting-Host: pogner.demon.co.uk:158.152.70.98 References: <38C7E515.29C42580@mindspring.com> X-Trace: news.demon.co.uk 952860443 nnrp-02:1646 NO-IDENT pogner.demon.co.uk:158.152.70.98 Organization: At Home Newsgroups: comp.lang.ada X-Complaints-To: abuse@demon.net Date: 2000-03-11T00:00:00+00:00 List-Id: gisle@spurv.ii.uib.no (Gisle S�lensminde) writes: > C has not 'in out' parameters, only 'in' parameters. To pass the > pointer to the string you can use system'address. str'address is > equivalent to &str in C. The following Ada code can replace > the Ada code of your last posting: Gisle, If you do this, you're missing a lot of typechecking. Certainly on GNAT the compiler has a deep understanding of "convention C" (this is covered in Annex B.3 (63) ff). I think the one you want is (68) -- a GNAT chars_ptr is (eventually) a System.Storage_Elements.Integer_Address -- but if your compiler doesn't handle this level of interfacing properly I think you should send it back for a refund! --------- strs.adb ----------------------------------------------------- with Interfaces.C.Strings; procedure Strs is procedure O_Str (O_Str : out Interfaces.C.Strings.Chars_Ptr); pragma Import (C, O_Str, "o_str"); procedure I_Str (I_Str : Interfaces.C.Strings.Chars_Ptr); pragma Import (C, I_Str, "i_str"); Str : Interfaces.C.Strings.Chars_Ptr; begin O_Str (Str); I_Str (Str); end Strs; ------------------------------------------------------------------------ --------- strs_c.c ----------------------------------------------------- #include #include char sig[] = "a message from o_str()"; void o_str(char **s) { *s = sig; } void i_str(char *s) { printf("i_str(%s).\n", s); } ------------------------------------------------------------------------ gcc -c strs_c.c gnatmake strs -largs strs_c.o -Simon