I know in C, before application can get started in main()
, some entity must:
- Initialize Global variables
- Set the stack pointer to the lowest stack area address(assuming stack grows upward)
Question 1- What's that entity that does this stuff? Who writes it?
Question 2- Are there additional things in C++?
I assume object constructors and initializations are all done during the course of application, after main()
main
when you run a program. The OS kernel also does a bunch. – Roosmain()
, captures the return value frommain()
, and then does any cleanup. It is normally written by the vendor who supplies your compiler and standard library, but may use code supplied by the host system. In C++, the compiler takes care of emitting code that ensures constructors of static objects at file scope are called beforemain()
- and possibly other statics as well - and (ideally) their destructors are called aftermain()
(in reverse order of construction). – Splittingstart
. That is the true entry point, it eventually calls main. It also calls acrtStartup
or something in Windows. – Hands