在C-ADA绑定应用程序传递字符串 [英] Passing strings in C-ADA binding application

查看:184
本文介绍了在C-ADA绑定应用程序传递字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何传递字符串从C函数ADA(C-ADA绑定)?

How can I pass strings from a C function to function in ADA (C-ADA binding)?

任何例子是AP preciated。

Any examples would be appreciated.

推荐答案

基本上,你可以创建在阿达端映射你的C函数子程序:

Basically, you would create a subprogram on the Ada side that maps you C function:

procedure Foo (C : Interfaces.C.Strings.chars_ptr);
pragma import (C, Foo, "foo");

这样从阿达你有机会获得富()

自定义是再提供一个更加友好的Ada版本,具有:

The custom is to then provide a more Ada friendly version, with:

procedure Foo (C : String) is
   S : Interfaces.C.Strings.chars_ptr := New_String (C);
begin
   Foo (S);
   Free (S);      
end Foo;

如果在另一方面的程序是写在阿达,你想从C调用它,你可以使用:

If on the other hand the procedure is written in Ada and you want to call it from C, you would use:

procedure Foo (C : Interfaces.C.Strings.chars_ptr);
pragma Export (C, Foo, "foo");

和从C,你可以调用:

extern void foo(char* c);
foo("bar");

这篇关于在C-ADA绑定应用程序传递字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆