In GNU C, you declare certain things about functions called in your program which help the compiler optimize function calls and check your code more carefully. The keyword __attribute__allows you to specify special attributes when making a declaration. This keyword is followed by an attribute specification inside double parentheses.
For example, please see the following code, where I am storing ADD function variables X and Y in CPU registers instead of stack using __attribute__.
// FASTCALL.c
#include <stdio.h >
__attribute__((fastcall,noinline)) int ADD (int X, int Y)
{
return X + Y;
}
int main () {
int Z = ADD (10, 20);
printf("\n Z = %d \n", Z );
}
.file "FASTCALL.c"
.text
.p2align 4,,15
.globl ADD
.type ADD, @function
ADD:
pushl %ebp
movl %esp, %ebp
leal (%edx,%ecx), %eax
popl %ebp
ret
.size ADD, .-ADD
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "\n Z = %d \n"
.text
.p2align 4,,15
.globl main
.type main, @function
main:
pushl %ebp
movl $20, %edx
movl %esp, %ebp
andl $-16, %esp
subl $16, %esp
movl $10, %ecx
call ADD
movl $.LC0, 4(%esp)
movl $1, (%esp)
movl %eax, 8(%esp)
call __printf_chk
leave
ret
.size main, .-main
.ident "GCC: (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3"
.section .note.GNU-stack,"",@progbits
In the above assembler code, you can find that X and Y are stored in edx, ecx registers instead of esp. If you want to check the time difference without and with __attrribute_, you can use clock_t in your code.