comp.lang.ada
 help / color / mirror / Atom feed
From: Al Johnston <sofeise@mindspring.com>
Subject: Re: ada to c interfaces and CHARS_PTR
Date: 2000/03/10
Date: 2000-03-10T05:02:30+00:00	[thread overview]
Message-ID: <38C8816B.835E8F87@mindspring.com> (raw)
In-Reply-To: 38C7E515.29C42580@mindspring.com

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 <stdio.h>
#include <stdlib.h>
#include <string.h>

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");
}






  parent reply	other threads:[~2000-03-10  0:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2000-03-10  0:00 ` tmoran
2000-03-10  0:00   ` Al Johnston
replies disabled

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