nginx 研究2


今天看了一下main的初步源码,第一行,就让我学到了一些东西


int ngx_cdecl
main(int argc, char *const *argv)

什么是ngx_cdecl

找到

#define ngx_cdecl



是个空定义,那么究竟是来干嘛的


查了一下,发现是跨平台时的一种约定。

http://en.wikipedia.org/wiki/X86_calling_conventions


简单来说,就是在不同的平台上,要遵守特定的标准,为了避免平台不同导致出的程序异常,在使用到平台特定的编译时,需要制定惯例


cdeclGCC RTL (C)CallerWhen returning struct/class, the calling code allocates space and passes a pointer to this space via a hidden parameter on the stack. The called function writes the return value to this address.
cdeclMicrosoft RTL (C)CallerWhen returning struct/class,
  • POD return values 32 bits or smaller are in the EAX register
  • POD return values 33-64 bits in size are returned via the EAX:EDX registers.
  • Non-POD return values or values larger than 64-bits, the calling code will allocate space and passes a pointer to this space via a hidden parameter on the stack. The called function writes the return value to this address.

上面的解释显然体现了两个不同平台的处理

MS只有在非POD情况下,才和GCC一样


POD:

将对象的各字节拷贝到一个字节数组中,然后再将它重新拷贝到原先的对象所占的存储区中,此时该对象应该具有它原来的值。


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值