Defining a GCC Shortcut Function

Ok, so I can call the function as fastcall CC, declaring it with __attribute__((fastcall)). How to define a function as fastcall?

Like, I have a caller code:

// caller.c

unsigned long func(unsigned long i) __attribute__((fastcall));

void caller() {
    register unsigned long i = 0;
    while ( i != 0xFFFFFFD0 ) {
        i = func(i);
    }
}

And function:

// func.c

unsigned long func(unsigned long i) {
    return i++;
}

This code func()compiles as cdecl , it pulls i from the stack, not from ecx (this is i386).

If I write unsigned long func(unsigned long i) __attribute__((fastcall));to func.c it just won’t compile saying

error: expected ‘,’ or ‘;’ before ‘{’ token

If I declare this in func.c in the same way as in caller.c, it will complain differently:

error: previous declaration of ‘func’ was here
+5
source share
2 answers

, .

Try:

__attribute__((fastcall)) unsigned long func(unsigned long i) ;
__attribute__((fastcall)) unsigned long func(unsigned long i) {
    return i++;
}

-

+8

- , .

unsigned long func(unsigned long i) __attribute__((fastcall)) // no semicolon here
{
    ... function ...
0

All Articles