Assuming that init is the last global object being initialized before main() (and we don’t need any command line argument), can I do something like:
struct int_main {
int_main ()
{
//... start code execution
}
}init;
int main ()
{
}
Asking the question in this way, because I am interested in knowing if main() assures anything other than:
- argc, argv from command line
- All global objects are initialized
before it
You would have a hard time catching any exception from theint_mainconstructor.Also you would have a hard time returning a process exit code with complete unwinding of the stack.
That’s mainly what
mainprovides in C++: a place to catch exceptions, and a means to return normally (not justexit) with a specified process exit code.Cheers & hth.,