What is the calling convention for the main function in C?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-14 01:36:39

问题


Each function in C must have a calling convention, but what is the calling convention for the main function (I think it is the cdecl calling convention but I am not sure)?


回答1:


That depends on the architecture and platform. A lot of x86 C runtime specifications require that main be cdecl, but it's by no means guaranteed.

The bottom line is you're not going to find this information in the C standard because the language is not tied to any one architecture. You might have more luck reading the documentation for the particular compiler(s) you're interested in.




回答2:


C language does not define calling convention but the processor architecture and development platform does. For X86 calling convention please check wiki https://en.wikipedia.org/wiki/X86_calling_conventions

Also, see ARM calling convention at below link http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042f/IHI0042F_aapcs.pdf

More on calling convention see below wiki link https://en.wikipedia.org/wiki/Calling_convention

Also, check discussion about MIPS calling convention at GCC MIPS-32 Calling Conventions / Stack Frame Definition



来源:https://stackoverflow.com/questions/45697594/what-is-the-calling-convention-for-the-main-function-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!