好的,所以我可以调用函数作为fastcall CC,方法是用__attribute__((fastcall))
声明它。
如何将函数本身定义为 fastcall?
例如,我有来电代码:
// caller.c
unsigned long func(unsigned long i) __attribute__((fastcall));
void caller() {
register unsigned long i = 0;
while ( i != 0xFFFFFFD0 ) {
i = func(i);
}
}
还有函数:
// func.c
unsigned long func(unsigned long i) {
return i++;
}
在这段代码中,func()
被编译为 cdecl,它从堆栈中提取 i,而不是从 ecx(这是 i386)。
如果我在 func.c 中编写 unsigned long func(unsigned long i) __attribute__((fastcall));
它就不会编译,说
error: expected ‘,’ or ‘;’ before ‘{’ token
如果我像在 caller.c 中那样在 func.c 中声明它,它会以另一种方式提示:
error: previous declaration of ‘func’ was here
最佳答案
属性必须在声明中应用,而不是在定义中。
尝试:
__attribute__((fastcall)) unsigned long func(unsigned long i) ;
__attribute__((fastcall)) unsigned long func(unsigned long i) {
return i++;
}
这样做的标准方法是将声明放在标题中,并让两个源文件都包含标题
关于c - GCC fastcall 函数定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7760736/