Misc: 那些放在函数定义前的 _cdecl , _stdcall, _fastcall 到底是什么鬼

如果看一些很底层的代码(比如很多库的代码,或者内核代码),会经常见到形如 _cdecl  ,  _stdcall (这个在Windows下的代码中很常见),  _fastcall (这个比较少见)这一类的东西,到底是什么?

这些其实是用来指示编译器做函数调用的时候,应该如何调用,比如说,

  a)参数的传递是放在寄存器中还是放在栈中

  b)参数是从左传到右还是从右传到左

  etc.

说得专业一点,就是calling convention. 

这些关乎系统底层ABI层面的东西。处理得不好,你的程序在链接的时候就会出现一堆的" Unresolved References" 错误(两个程序在ABI层面上不相容)。

当然一般high-level的程序不需要理会这些。

 

Reference:

  https://en.wikibooks.org/wiki/Embedded_Systems/Mixed_C_and_Assembly_Programming#Calling_Conventions

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

 

 

The Old New Things:

  The history of Calling Conventions, Part I

  The history of Calling Conventions, Part II

  The history of Calling Conventions, Part III

  The history of Calling Conventions, Part IV, ia64

  The history of Calling Conventions, Part V, amd64

 

 

 

 

 

 

 

 

 

 

 

 

 

:)

posted @ 2016-05-15 20:40  walkerlala  阅读(191)  评论(0编辑  收藏  举报