Re:What happens before main() is executed in C and why is it...
by nebulous1 on Friday May 04, 2018 @01:23PM
(#16996331)
This seems to be concentrating on what the system loader is doing without mentioning whatever the statically linked standard library gets up to before calling the main function?
[ Parent
| on HN ]
Re:What happens before main() is executed in C and why is it...
by jwr on Friday May 04, 2018 @01:28PM
(#16996385)
On microcontrollers, you often don't have a standard library, or if you do, it is limited, and doesn't do things before main. The article describes pretty well what happens on a microcontroller.
I would add that in some (most?) environments, the code that gets executed before main() is easily accessible: it sits in files within the project (written in assembly most of the time).
Re:What happens before main() is executed in C and why is it...
by nebulous1 on Friday May 04, 2018 @01:44PM
(#16996548)
Cool, he is talking about the loader though, which would imply that this is all language independent? Except for where he mentions things getting executed before main in C++, which I'm assuming would be the doings of the C++ standard library.
Re:What happens before main() is executed in C and why is it...
by monocasa on Friday May 04, 2018 @01:53PM
(#16996647)
It's still pretty language independent. Qemu for instance is a c codebase that depends on static initialization functions that run before main to register the different components.
Re:What happens before main() is executed in C and why is it...
by jldugger on Friday May 04, 2018 @02:14PM
(#16996842)
In any other context, yes, you're missing C library predecessors to main(). But it's specifically referencing embedded systems, which is why hardware initialization and memory segments are mentioned.