Re:What happens before main() is executed in C and why is it...
by saagarjha on Friday May 04, 2018 @07:10PM
(#16999172)
Here's what works on my Mac, compiled with clang -m32.
Of course, this won't work at all on x86_64 because arguments are passed on registers instead of the stack.
[ Parent
| on HN ]
Re:What happens before main() is executed in C and why is it...
by doomjunky on Saturday May 05, 2018 @12:38AM
(#17000356)
On Windows this dependes on the calling convention. The calling convention determines whether function arguments are passed: In order or in reverse order. Who takes care of cleaning the stack: caller or callee? And even if the arguments are passed by stack or CPU registers.
In Visual Studio you can control this behavoir with the __cdecl, __clrcall, __stdcall, __fastcall, __thiscall, __vectorcall [1] calling convention function prefixes, but this also depends on the optimization options [2] of the compiler.
Passing arguments via CPU registers has a huge preformance benefit, but also some drawbacks.
Re:What happens before main() is executed in C and why is it...
by saagarjha on Saturday May 05, 2018 @07:53PM
(#17004528)
> Passing arguments via CPU registers has a huge preformance benefit, but also some drawbacks.
Like what?
Re:What happens before main() is executed in C and why is it...
by pjmlp on Saturday May 05, 2018 @08:36PM
(#17004681)
On architectures like x86, the set of registers is limited and some are special, so there is some contention going on.