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,691379720c755924,start X-Google-Attributes: gid103376,public From: Paul Chardon Subject: String Allocation when Interfacing C with Ada Date: 1996/12/05 Message-ID: <32A6D464.41C67EA6@avions.aerospatiale.fr>#1/1 X-Deja-AN: 202496668 content-type: text/plain; charset=us-ascii mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 3.0 (X11; I; SunOS 4.1.3_U1 sun4m) Date: 1996-12-05T00:00:00+00:00 List-Id: Hello, I'm writing a C program using a string, this string is passed as parameter to an Ada subprogram in order to modify its value. Is there any problem of allocation or deallocation in this case. For instance: -- The main C program void Handle_String(char * s); main () { char *a_string strcpy(a_string,"high"); printf("String Value : %s \n", A_String); adainit(); Handle_String(A_String); printf("String Value : %s \n",A_String); /* Print only value token in account when using strcpy in the Ada subprogram, not when using "Ada allocation" */ adafinal(); } -- The imported Ada subprogram with Interfaces.C.Strings; with Text_Io; procedure Handle_String(S : in out Interfaces.C.Strings.Chars_ptr) is procedure C_Strcpy (Target : out Interfaces.C.Strings.Chars_Ptr; Source : in Interfaces.C.Strings.Chars_Ptr); pragma import(C, C_Strcpy,"strcpy"); begin -- THAT CALL S := Interfaces.C.Strings.New_String ("Value not token in account"); -- when I put only this call, no value is printed in the C -- program -- OR THIS OTHER CALL C_Strcpy(S, Interfaces.C.Strings.New_String ("Value token in account")); -- When I do that copy instead of the first allocation call, the -- good value is printed in C main function end Handle_String; pragma Export(C, Handle_String, "Handle_String"); If anyone can explain why it doesnt works in the first call case. Thanks in advance, Paul.