c - 快速调用 GCC 示例

标签 c gcc compiler-construction fastcall

有人可以提供一个与 gcc 一起使用的 fastcall 示例吗?如果可能,您能否在不使用 fastcall 的情况下提供等效调用并解释它们有何不同?

最佳答案

给定函数调用在 C 代码中的显示方式没有区别。唯一的区别在于函数声明。 GCC manual有更多详细信息。

$ cat fastcall.c
extern void foo1(int x, int y, int z, int a) __attribute__((fastcall));
extern void foo2(int x, int y, int z, int a);

void bar1()
{
    foo1(99, 100, 101, 102);
}

void bar2()
{
    foo2(89, 90, 91, 92);
}

$ gcc -m32 -O3 -S fastcall.c -o -
.
.
bar1:
.
.    
    movl    $100, %edx
    movl    $99, %ecx
    movl    $102, 4(%esp)
    movl    $101, (%esp)
    call    foo1
.
.
bar2:
.
.
    movl    $92, 12(%esp)
    movl    $91, 8(%esp)
    movl    $90, 4(%esp)
    movl    $89, (%esp)
    call    foo2

关于c - 快速调用 GCC 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/672268/

相关文章:

gcc - CMake (cotire) 预编译头文件并禁用警告

linux - 裸机交叉编译器输入

c++ - MSVC 是否自动优化双核架构上的计算?

C - 为什么只有 char 数组 null 终止?

c - 使用 fseek 函数读取文件时出现问题

c - 线程还是进程?拥有与数据无关的任务,使用什么更好?

c++ - 使用 shared_ptr 和 glutInit 导致段错误

c++ - FMOD 编译问题

C并行垃圾收集器,如何避免锁定主线程

c - 多个线程如何更改互斥锁锁定的静态变量