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,46f08bac1c72057b,start X-Google-Attributes: gid103376,public From: Jean-Marc Bourguet Subject: Problem when interfacing C with Ada Date: 1996/08/29 Message-ID: #1/1 X-Deja-AN: 177174271 sender: bourguet@su2 organization: Faculte Polytechnique de Mons, Service d'Electronique x-access: 16 727 newsgroups: comp.lang.ada Date: 1996-08-29T00:00:00+00:00 List-Id: 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 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