VC++ 中有 _Complex 语法的解决方法吗?
我有一个用 MinGW 编译的库,它支持 C99 关键字 _Complex。我想将此库与 MSVC++ 2010 编译器一起使用。我尝试暂时关闭所有 _Complex 语法代码,以便它可以编译。我发现大多数其他功能在 MSVC++ 中运行良好。现在我想启用具有 _Complex 定义的部分,但真的不知道如何操作。
显然我无法在 MSVC++ 中重新编译它,因为该库需要 C99 功能等。但是,我觉得放弃它并寻找替代品是一种浪费,因为它与大多数其他功能完美配合。
我想我可以编写需要 _Complex 语法的 API 的包装器,并使用 MinGW GCC 对其进行编译,然后它将能够导入到我的 MSVC 项目中。但我仍然想知道这个问题是否有更好的解决方法,比如在 VC++ 中编译 C99 复数语法时人们处理问题的“标准”方式是什么?
兴。
I've got a library compiled with MinGW which supports the C99 Keywords, _Complex. I'd like to use this library with MSVC++ 2010 compiler. I've tried to temporarily switch off all the _Complex syntax code, so that it compiles. I found most of the other functions worked fine in MSVC++. Now I want to enable the parts with _Complex definition, but really don't know how to.
Obviously I can't recompile it in MSVC++ as the library asks for C99 features, etc. However, I feel like it is such a waste to give it up, and look for substutions, because it works perfect with most other functions.
I think I can write wrappers of the APIs that require _Complex syntax and compile it with MinGW GCC then it will be able to import into my MSVC project. But I still want to know if there is any better workaround of this problem, like what is the "standard" way people dealing with problem when compile C99 complex number syntax in VC++?
Xing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 C 标准(C11 §6.2.5 ¶13;C99 具有大致相同的语言):
我面前没有 C++ 标准,但是
中定义的复杂类型模板有相同的要求;这是为了兼容性。因此,您可以使用 & 重写 C 函数。返回 double _Complex 类型的值作为 C++ 函数,采用 &返回
std::complex类型的值
;只要 C++ 端的名称修改已关闭(通过extern "C"
),双方都将兼容。像这样的事情可能会有所帮助:
From the C Standard (C11 §6.2.5 ¶13; C99 has approximately the same language):
I don’t have the C++ Standard in front of me, but the complex type templates defined in
<complex>
have the same requirement; this is intended for compatibility.You can therefore re-write C functions taking & returning values of type
double _Complex
as C++ functions taking & returning values of typestd::complex<double>
; so long as name-mangling on the C++ side has been turned off (viaextern "C"
) both sides will be compatible.Something like this might help: