如何#define __forceinline 内联?
我有一些 Microsoft 代码 (XLCALL.CPP),我正在尝试使用 CodeBlocks/MinGW 进行编译。
在这一行,我收到编译时错误:
__forceinline void FetchExcel12EntryPt(void)
这是我收到的错误消息:
XLCALL.CPP|36|错误:预期的构造函数、析构函数或类型 “void”之前的转换
此错误是预料之中的,因为 __forceinline 是 Microsoft 特定于该语言的附加内容,GCC 无法识别。
因此,为了进行编译,我尝试在 CodeBlocks(项目构建选项/编译器设置/#defines)中添加 thiese 定义:
#define __forceinline inline
#define __forceinline
但是我仍然遇到相同的错误。
如果在对话框中我没有指定 #define 预处理器命令(即:__forceinline inline
),这就是我得到的:
XLCALL.CPP|36|错误:数字常量之前应有非限定 ID
有没有办法编译这样一段代码,不使用 Visual C++?
I have some Microsoft code (XLCALL.CPP) which I am trying to compile with CodeBlocks/MinGW.
At this line I get a compile time error:
__forceinline void FetchExcel12EntryPt(void)
This is the error message I get:
XLCALL.CPP|36|error: expected constructor, destructor, or type
conversion before 'void'
This error is expected, because __forceinline is a Microsoft specific addition to the language, not recognized by GCC.
So, to get things compile, I try to add thiese defines in CodeBlocks (Project Build Options/Compiler Settings/#defines):
#define __forceinline inline
#define __forceinline
However I still get the same error.
If in the dialog I do not specify the #define preprocessor command (i.e.: __forceinline inline
), this is what I get:
XLCALL.CPP|36|error: expected unqualified-id before numeric constant
Is there a way to compile such a piece of code, without using Visual C++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您在评论中所指出的,语法是 __forceinline=inline,因为这些设置会变成
-D
GCC 选项。请注意,
inline
是向 GCC 强烈提示该函数应该内联,但并不保证一定会内联。 GCC 等价于__forceinline
是always_inline
属性 - 例如此代码:或等效于此设置:(
但这很可能是不必要的:如果在使用 MSVC 编译时有一些特别好的理由强制此函数,那么当使用完全不同的版本时,该原因很可能无效编译器!)
The syntax is
__forceinline=inline
, as you've noted in the comments, because these settings get turned into-D
options to GCC.Note that
inline
is a strong hint to GCC that the function should be inlined, but does not guarantee it. The GCC equivalent of__forceinline
is thealways_inline
attribute - e.g. this code:or equivalently this setting:
(But this might well be unnecessary: if there was some particularly good reason for forcing this function to be inlined when compiling with MSVC, that reason may well not be valid when using a completely different compiler!)