C/C++不透明指针库
是否已经编写了库/标头来使用不透明指针/句柄管理 C++ 对象?
我可以自己写一个,但我宁愿使用已经制定的解决方案,特别是如果它具有 Fortran 绑定。
我的具体要求是:
- 包装器生成工具(我的想法是使用 boost 预处理器)
- 通过整数(而不是原始指针)句柄(à la mpi)处理对象,以提供句柄验证和特殊值以及 64 位 fortran 的一些可移植性。
谢谢
Is there library/header already written to manage C++ objects from C using opaque pointers/handles?
I can write one myself, but I would rather use already made solution, especially if it has fortran bindings.
my specific requirements are:
- wrapper generation facility (my thought is to use boost preprocessor)
- handling objects through integer (rather than raw pointers) handles (à la mpi) to provide handle verification and special values and some portability with 64-bit fortran.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 C++ 中,只需提供函数
和 C 标头
即可。您所需要的应该是具有与
void*
之间转换的适当访问器。您的 Fortran 编译器可能与
extern "C"
兼容(特别是如果它与 C 静态库兼容),或者您的 C++ 编译器可能具有extern "Fortran"
。请参阅他们的手册。您也许可以找到一个代码生成器来为您执行此操作。如果可以的话,手动执行当然更安全。
In C++, simply provide functions
and a C header
Appropriate accessors with casts to and from
void*
should be all you need.Your Fortran compiler may be compatible with
extern "C"
(particularly if it's compatible with C static libraries) or your C++ compiler may haveextern "Fortran"
. See their manuals.You might be able to find a code generator to do this for you. If you can, doing it manually is safer of course.
一旦你有了一个看起来像 C 的接口,对于 Fortran 绑定,你可能可以使用 ISO C 绑定来指示 Fortran 编译器如何调用 C 接口。一般来说,ISO C Binding 提供了一个标准和规范。 Fortran 和 Fortran 接口的可移植方法C 是双向的,尽管两种语言都有一些功能不受支持。以下是可能(未经测试)用于设置 Fortran 绑定的示例接口:
Once you have an interface that looks like C, for the Fortran binding probably you can use the ISO C Binding to instruct the Fortran compiler how to call the C interface. Generally the ISO C Binding provides a standard & portable method of interfacing Fortran & C in both directions, though there are some features of both languages that aren't supported. The following is an example interface that might (untested) work to setup a Fortran binding: