__cdecl or __stdcall on Windows?

前端 未结 3 519
悲哀的现实
悲哀的现实 2020-12-04 07:06

I\'m currently developing a C++ library for Windows which will be distributed as a DLL. My goal is to maximize binary interoperability; more precisely, the functions in my D

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 07:25

    The biggest difference in the two calling conventions is that "__cdecl" places the burden of balancing the stack after a function call on the caller, which allows for functions with variable amounts of arguments. The "__stdcall" convention is "simpler" in nature, however less flexible in this regard.

    Also, I believe managed languages use stdcall convention by default, so anyone using P/Invoke on it would have to explicitly state the calling convention if you go with cdecl.

    So, if all of your function signatures are going to be statically defined I would probably lean toward stdcall, if not cdecl.

提交回复
热议问题