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 calls New_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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With