The reason is not because of the OS (it simply adjust the relocation table after copying the executable image in memory BEFORE jumping in it, so the exe itself has no role in that) but because of how C++ works. Objects has constructors and destructors. Try this
#include <iostream>
class A
{
public:
A() { std::cout << "A created" << std::endl; }
~A() { std::cout << "A destroyed" << std::endl; }
};
A global_a;
int main()
{
std::cout << "this is main" << std::endl;
return 0;
}
The output will be
A created
this is main
A destroyed
Global objects must be created/destroyed outside the scope of main. This is not an OS requirement, but a requirement for the C++ specification. mainCRTSturtup
is the "bridge" between the OS (that has no clue about the app language specifications: it just want an address to be called) and a language like C++ that requires some code (constructors and destructors of global objects) to be executed independently of the main() function.
2 bugs found. > recompile ... 65534 bugs found. :doh:
modified on Sunday, August 14, 2011 4:33 AM