Are there any problems when using pure C (not class-wrapped) functions in C++ application?

≯℡__Kan透↙ 提交于 2019-12-24 03:35:10

问题


I am planning to use pure C MPI library in C++ application, I don't want to add unnecessary bloat by running eg. Boost MPI layer that wraps all stuff in the MPI::<func> classes.

Is there anything I should be aware of?


回答1:


You should wrap all your includes for C-headers in an extern "C" block in order to avoid problems with the name mangling of C++ compilers.

extern "C" {
    // include C-headers
}

Read more here.




回答2:


Not really, as most libraries are prepared to be included in a C++ compiler (if not, you can do as Space Cowboy above suggests). However, I would advice you (if you don't mind) on reconsidering boost MPI. It doesn't add unnecessary bloat, and gives you a more comprehensive interface to MPI in an object-oriented environment. It adds more semantics to types being transferred via MPI, and even gives you more "functional" operators, such as using functors for the calculation operations (e.g. reduce), etc. The ammount of code they add is negligible, and most of the time, there is no run-time overhead, as abstractions are implemented via template metaprogramming.



来源:https://stackoverflow.com/questions/4114463/are-there-any-problems-when-using-pure-c-not-class-wrapped-functions-in-c-ap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!