【发布时间】:2011-10-13 21:39:33
【问题描述】:
好的,所以我可以 call 充当 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
如果我在 func.c 中声明它的方式与在 caller.c 中的方式相同,它会以另一种方式抱怨:
error: previous declaration of ‘func’ was here
【问题讨论】: