Linux下如何指定调用约定(calling convention)

原文地址::http://www.linuxidc.com/Linux/2011-04/35032.htm


相关文章

1、Linux下如何指定调用约定(calling convention)----http://blog.sina.com.cn/s/blog_81fcea160101mpoo.html

2、__stdcall和__cdecl的区别----http://www.cnblogs.com/zhangchaoyang/articles/2725189.html



Windows下的调用约定可以是stdcall/cdecl/fastcall,这些标识加在函数名前面,如:

int __stdcall funca()

但在Linux下,如按照上面写法后,编译程序将导致编译错误,Linux下正确的语法如下:

int __attribute__((__stdcall__)) funca()

int __attribute__((__cdecl__)) funca()

Linux下如果函数不指定调用约定,默认的情况应该是__attribute__((__cdecl__))

int __attribute__((__cdecl__)) myfunc(int i, int j, int k)
{
    return i+j+k;
}

 080483d0 <myfunc>:
 80483d0:    55                       push   %ebp
 80483d1:    89 e5                    mov    %esp,%ebp
 80483d3:    8b 45 0c                 mov    0xc(%ebp),%eax
 80483d6:    03 45 08                 add    0x8(%ebp),%eax
 80483d9:    03 45 10                 add    0x10(%ebp),%eax
 80483dc:    5d                       pop    %ebp
 80483dd:    c3                       ret    
 80483de:    66 90                    xchg   %ax,%ax

int __attribute__((__stdcall__)) myfunc(int i, int j, int k)
{
    return i+j+k;
}

 080483d0 <myfunc>:
 80483d0:    55                       push   %ebp
 80483d1:    89 e5                    mov    %esp,%ebp
 80483d3:    8b 45 0c                 mov    0xc(%ebp),%eax
 80483d6:    03 45 08                 add    0x8(%ebp),%eax
 80483d9:    03 45 10                 add    0x10(%ebp),%eax
 80483dc:    5d                       pop    %ebp
 80483dd:    c2 0c 00                 ret    $0xc


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值