问题
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