Why does the Windows API use the stdcall calling convention?

Source: Internet
Author: User

User-aware
Links: https://www.zhihu.com/question/31453641/answer/52001143
Source: Know
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.

Answer 1:
Do you want to ask why Windows C + + is full of stdcall or WINAPI, not cdecl calling convention? The reason is simple and straightforward, and the generated code is small. WINAPI is a macro definition of stdcall, in fact it is one thing. StdCall convention is called by the caller to clear the stack, the return instruction with a fallback stack parameters on it, the caller himself a ret n is done. The CDECL convention is that the caller will clear the stack, that is, every caller after the function call completes, to each caller to pull the ESP to change the stack status back. The disadvantage of stdcall is that it cannot support a variable number of parameters, because the callee must determine the number of parameters in order to clear the stack itself. I remember the old Win32 API has only one API to support variable-length parameters, so only she is cdel and not stdcall, from User32 wsprintf.
Posted on 2015-06-2046?12

Answer 2:
Save a bit of memory, the stack top pointer back to this command, only need to implement a function, and do not need every call to the end of the implementation. The bunch of Microsoft programmers that came out of the dos640k era have all sorts of perverted ways of saving memory. Start-up phase try not to load COM components, do not carry on to do a Super Lite version of COM. Not to mention the various kinds of abnormal memory methods inside MFC.
Posted on 2015-06-29

Sum up:
__stdcall The callee cleans up the stack, generates small execution code, and saves memory. Disadvantage: mutable parameters are not supported. The use of __stdcall by Windows APIs is a historical issue.

Why does the Windows API use the stdcall calling convention?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.