GCC快速调用函数定义
好的,我可以调用函数作为快速调用CC,方法是用GCC快速调用函数定义,c,gcc,C,Gcc,好的,我可以调用函数作为快速调用CC,方法是用\uuuu属性((快速调用))声明它。 如何将函数本身定义为fastcall 比如,我有呼叫者代码: // caller.c unsigned long func(unsigned long i) __attribute__((fastcall)); void caller() { register unsigned long i = 0; while ( i != 0xFFFFFFD0 ) { i = func(
\uuuu属性((快速调用))
声明它。
如何将函数本身定义为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)
如果我写unsigned long func(unsigned long I)\uuuu属性(fastcall))在func.c中,它只是不编译,说
error: expected ‘,’ or ‘;’ before ‘{’ token
如果我像在caller.c中一样在func.c中声明它,它会以另一种方式抱怨:
error: previous declaration of ‘func’ was here
属性必须应用于声明中,而不是定义中
尝试:
执行此操作的标准方法是将声明放在头中,并使两个源文件都包含头问题是在属性后放置分号。你需要
unsigned long func(unsigned long i) __attribute__((fastcall)) // no semicolon here
{
... function ...
func.c:2:错误:“func”func.c:1:错误:“func”的上一个声明无效here@einclude尝试将属性放在定义之前。最新答复
unsigned long func(unsigned long i) __attribute__((fastcall)) // no semicolon here
{
... function ...