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)?
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.
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
© 2022 - 2024 — McMap. All rights reserved.
main
has the same calling convention as any other function;_start
(a typical entry point in ELF), on the other hand, is cdecl and must handle converting to the native calling convention for main (among other things) ... don't know why_start
doesn't use the native calling convention... probably because in Linux, the binfmt_elf source is in the ./fs (file system) directory instead of ./arch and 32 bit x86 used cdecl, so it was easy to be lazy and force every non-cdecl platform to require some assembly or compiler specific intrinsics in their libc. – Bush