Ada's strings are NOT null terminated like C's. I have a requirement in a C-Ada binding application where I need to pass a string that is allocated in Ada code to a C function. How will C recognize Ada strings in here as strings in C are usually simple char array terminated by a null char while this is not the case in Ada?
Any examples would be appreciated!
Expanding on @manuBriot's answer to your previous question on this topic, note that the convenient wrapper procedure Foo
callsNew_String
on the incoming Ada String
to obtain a chars_ptr
.
procedure Foo (C : String) is
S : Interfaces.C.Strings.chars_ptr := New_String (C);
begin
…
end Foo;
Note also that New_String
"is equivalent to New_Char_Array(To_C(Str))
." When passed an Ada String
, To_C
sets Append_Nul
to True
by default. As a result, Ada Foo
calls C foo
with a properly null
terminated C string.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.