stdcall and cdecl

后端 未结 9 886
旧时难觅i
旧时难觅i 2020-11-27 09:17

There are (among others) two types of calling conventions - stdcall and cdecl. I have few questions on them:

  1. When a cdecl fun
9条回答
  •  Happy的楠姐
    2020-11-27 10:11

    The caller and the callee need to use the same convention at the point of invokation - that's the only way it could reliably work. Both the caller and the callee follow a predefined protocol - for example, who needs to clean up the stack. If conventions mismatch your program runs into undefined behavior - likely just crashes spectacularly.

    This is only required per invokation site - the calling code itself can be a function with any calling convention.

    You shouldn't notice any real difference in performance between those conventions. If that becomes a problem you usually need to make less calls - for example, change the algorithm.

提交回复
热议问题