From: Paul Chardon <paul.chardon@avions.aerospatiale.fr>
Subject: String Allocation when Interfacing C with Ada
Date: 1996/12/05
Date: 1996-12-05T00:00:00+00:00 [thread overview]
Message-ID: <32A6D464.41C67EA6@avions.aerospatiale.fr> (raw)
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.
next reply other threads:[~1996-12-05 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-12-05 0:00 Paul Chardon [this message]
1996-12-06 0:00 ` String Allocation when Interfacing C with Ada Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox