为什么我应该在C ++中而不是C中设置插件接口 [英] Why should I setup a plugin interface in c++ instead of c

查看:69
本文介绍了为什么我应该在C ++中而不是C中设置插件接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我的上一个

As a result of my previous questions I asked myself: Is it usefull at all to setup a C++ interface for a plugin system? The following points are speaking against it:

  • 不同的编译器及其版本之间没有通用的ABI,内存中的对象没有通用的布局
  • 没有直接的班级出口.您必须出口工厂和破坏者.如果您的对象被其他仅delete个对象(例如智能指针)持有,则会出现问题.
  • STL的不同实现,您不能将std::list<T>传递给插件
  • Boost之类的已使用库的不同版本
  • No common ABI between different compilers and their versions, no common layout of the objects in memory
  • No direct class export. You have to export factories and destructors. Problems arises if your objects are held by other objects which only delete them, for example smart pointers.
  • Different implementations of the STL, you can't pass a std::list<T> to the plugin
  • Different versions of used libraries like Boost

如果您将自己限制在C ++语言的其余部分,则几乎会遇到"C子集".使用C ++有什么要说的吗? Qt-Toolkit如何解决上述问题?

If you restrain yourself to the remaining parts of the C++ language you nearly end up with the "C subset". Are there any points speaking for using C++? How do the Qt-Toolkit solve the mentioned problems?

备注:我主要是指Linux系统.不过,我对其他平台上的解决方案感兴趣.

Remark: I'm referring mostly to the Linux system. Nevertheless I'm interested in solutions on other platforms.

其他问题:使用C接口有什么问题? struct s的内存布局?应该避免使用C的哪些语言部分?

Additional question: What are the problems using a C interface? The memory layout of structs? Which language parts of C should be avoided?

推荐答案

尽管这更多地是关于如何"而不是为什么",但是您可能对

Although this is more about the "how" than the "why", you may be interested in the (not yet)Boost.Extension library, as well as the author's blog on the topic.

对于为什么"部分,我的2分(加拿大):取决于受众(插件编写者)以及应用程序及其插件之间接口的丰富程度:

For the "why" part, my 2 (Canadian) cents: It depends on the audience (the plugin writers) and on the richness of the interface between your application and its plugins:

  • 如果受众众多或种类繁多,则C ++插件系统的局限性(使插件方和应用程序方在编译器和库版本方面保持同步)变得不切实际,并且C接口更易于维护.如果受众群体较小,同质或在您的控制之下,那么这些问题就不那么重要了.
  • 如果接口丰富(手工挥舞着"rich"的确切含义),则C接口编写起来可能会很麻烦,并且平衡会倾斜到C ++一侧.

但是,第一个条件(受众)更为重要,因此,只有在受众是同质的并且该接口显着受益于表达能力的情况下,C ++接口才有意义.

However, the first criterion (the audience) is more important, and a C++ interface thus makes sense only if the audience is homogeneous and the interface significantly benefits from the expressiveness gains.

这篇关于为什么我应该在C ++中而不是C中设置插件接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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