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,ef6c792702c0ff46 X-Google-Attributes: gid103376,public From: Al Johnston Subject: Re: ada to c interfaces and CHARS_PTR Date: 2000/03/10 Message-ID: <38C8816B.835E8F87@mindspring.com>#1/1 X-Deja-AN: 595483005 Content-Transfer-Encoding: 7bit References: <38C7E515.29C42580@mindspring.com> X-Accept-Language: en X-Server-Date: 10 Mar 2000 05:02:30 GMT Content-Type: text/plain; charset=us-ascii Organization: MindSpring Enterprises Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-03-10T05:02:30+00:00 List-Id: Okay.. Not only did I not know how to write ada to c interface code, I apparently have forgotten to write basic c code as well. In case anyone else doesn't know how to use CHARS_PTR in an interface to c, here is what seems to work... I make no claim that it is correct. Runs on RH6.1/x86/gnat3.12. with text_io; with interfaces.c.strings; use interfaces.c.strings; package body a_sub is procedure a_sub is procedure c_sub(in_strg_fml : CHARS_PTR; inout_strg_fml : in out CHARS_PTR; accss_strg_fml : access CHARS_PTR); pragma import(c,c_sub,"c_sub"); in_strg_act : CHARS_PTR; inout_strg_act : CHARS_PTR; accss_strg_act : aliased CHARS_PTR; begin text_io.put_line(" in a_sub"); in_strg_act := NEW_STRING("I am here"); c_sub(in_strg_act, inout_strg_act, accss_strg_act'access); text_io.put_line(" He said ==>> " & VALUE(inout_strg_act) & " << =="); text_io.put_line(" He said ==>> " & VALUE(accss_strg_act) & " << =="); text_io.put_line(" out a_sub"); end a_sub; end a_sub; #include #include #include void c_sub(char *in____strg_fml, char **inout_strg_fml, char **accss_strg_fml) { char t_buffer[50]; printf(" in c sub\n"); sprintf(t_buffer," you said => %s <==",in____strg_fml); printf("%s\n",t_buffer); *inout_strg_fml = strdup(t_buffer); *accss_strg_fml = strdup(t_buffer); printf(" out c sub\n"); }