who calls the main function?
Printable View
who calls the main function?
It varies from system to system. Set a breakpoint at the first instruction in main and have a look at the stack trace.
The C(++) runtime will initialize various things and then will call the main() function. What happens before main() is called, heavily depends on the compiler vendor and on the platform the program is compiled for IMHO. You could set a breakpoint at the beginning of main() and walk thru the call stack, if you're curious. For VC++6.0 and W2k the call stack contains:I have to admit that I never bothered with the startup process - didn't have to.Code:main() line 31
mainCRTStartup() line 206 + 25 bytes
KERNEL32! 77e87d08()
This ans is specific to VC not standard c++. In VC
mainCRTStartup (define in CRT0.C file) call main. But if you want you can change the entry point by specify the /ENTRY switch. Here is a simple program which has Zee entry point rather than main.
Hope it helps.Code:#pragma comment(linker, "/ENTRY:Zee")
int _stdcall Zee()
{
return 0;
}