comp.lang.ada
 help / color / mirror / Atom feed
* ada to c interfaces and CHARS_PTR
@ 2000-03-09  0:00 Al Johnston
  2000-03-09  0:00 ` Preben Randhol
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Al Johnston @ 2000-03-09  0:00 UTC (permalink / raw)


I have been trying (for longer than I care to admit) to use the
following c subroutine from
ada:

--- begin c_sub.c ---
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void sub(const char *in_strg_fml,char **inout_strg_fml)
{
  char t_buffer[25];
  printf("      in  c sub\n");

  sprintf((char *)&t_buffer,"        you said => %s <==\0",in_strg_fml);

  *inout_strg_fml = strdup(t_buffer);
  printf("        %s\n",*inout_strg_fml);

  printf("      out c sub\n");
}
---- end c_sub.c ----

I wish to use the type CHARS_PTR from the ada.c.interface.strings
package.
Using this type to interface with c is the whole point of this
exercise.  Below  is the
section of ada code that attempts to use the above routine.  The program
cores
when the c routine returns.  I have not been able to find any examples
using
the CHARS_PTR type to interface with c (RM, Rat, GNAT adainc src).


---- begin a_sub.adb ----
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);
    pragma import(c,c_sub,"sub");

    in_strg_act    : CHARS_PTR;
    inout_strg_act : CHARS_PTR := NULL_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);
text_io.put_line("----------");
    text_io.put_line("    He said ==>> " & VALUE(inout_strg_act) & " <<
==");
    text_io.put_line("  out a_sub");
  end a_sub;

end a_sub;
---- end a_sub.adb ----

Some one please explan how this is done (using CHARS_PTR).

thanks.

-al





^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2000-03-15  0:00 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-09  0:00 ada to c interfaces and CHARS_PTR Al Johnston
2000-03-09  0:00 ` Preben Randhol
2000-03-09  0:00   ` Al Johnston
2000-03-09  0:00 ` Gisle S�lensminde
2000-03-09  0:00   ` Al Johnston
2000-03-13  0:00     ` Robert Dewar
2000-03-15  0:00       ` Al Johnston
2000-03-11  0:00   ` Simon Wright
2000-03-14  0:00     ` Al Johnston
2000-03-15  0:00       ` tmoran
2000-03-15  0:00         ` Al Johnston
2000-03-15  0:00       ` Robert Dewar
2000-03-10  0:00 ` Al Johnston
2000-03-10  0:00 ` tmoran
2000-03-10  0:00   ` Al Johnston

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox