From: Jean-Marc Bourguet <bourguet@muelec.fpms.ac.be>
Subject: Problem when interfacing C with Ada
Date: 1996/08/29
Date: 1996-08-29T00:00:00+00:00 [thread overview]
Message-ID: <sgloeymsah.fsf@su2> (raw)
When compiling the following program which interfaces C with Ada, I
don't optain the expected result; the display of
an Ada string
a C string
But I get
an Ada string
<an empty line>
I'm using gnat 3.05 on an Sun running Solaris 2.5.
I'd appreciate any help.
Here are the files:
-- main.adb
with Util;
procedure Main is
S : Util.String_Pointer;
begin
S := new String'("an Ada string");
Util.Display_String_Pointer (S);
Util.C_Function;
end Main;
-- util.ads
with Interfaces.C.Strings;
package Util is
package C
renames Interfaces.C;
type String_Pointer is access String;
function To_String_Pointer (S : C.Strings.Chars_Ptr) return String_pointer;
pragma Export (C, To_String_Pointer, "to_string_pointer");
procedure Display_String_Pointer (S : String_Pointer);
pragma Export (C, Display_String_Pointer, "display_string_pointer");
procedure C_Function;
pragma Import (C, C_Function, "c_function");
end Util;
-- util.adb
with Interfaces.C.Strings;
with Ada.Text_Io;
package body Util is
function To_String_Pointer (S : C.Strings.Chars_Ptr) return String_pointer
is
begin -- To_String_Pointer
return new String'(C.Strings.Value (S));
end To_String_Pointer;
procedure Display_String_Pointer (S : String_Pointer)
is
begin -- Display_String_Pointer
Ada.Text_Io.Put_Line (S.all);
end Display_String_Pointer;
end Util;
/* c_function.c */
typedef struct FAT_POINTER { char *a; void *b;} string_pointer;
string_pointer to_string_pointer (char *);
void display_string_pointer (string_pointer);
void c_function (void)
{
string_pointer string;
string = to_string_pointer ("a C string");
display_string_pointer (string);
}
--
Jean-Marc Bourguet Service d'Electronique
Faculte polytechnique de Mons
Email : bourguet@muelec.fpms.ac.be Mons, Belgique
reply other threads:[~1996-08-29 0:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox