Click to See Complete Forum and Search --> : main function


Atul Kothari
July 23rd, 2002, 05:47 AM
who calls the main function?

cup
July 23rd, 2002, 07:12 AM
It varies from system to system. Set a breakpoint at the first instruction in main and have a look at the stack trace.

Gabriel Fleseriu
July 23rd, 2002, 07:18 AM
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:
main() line 31
mainCRTStartup() line 206 + 25 bytes
KERNEL32! 77e87d08()

I have to admit that I never bothered with the startup process - didn't have to.

Zeeshan
July 23rd, 2002, 08:48 AM
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.


#pragma comment(linker, "/ENTRY:Zee")

int _stdcall Zee()
{
return 0;
}


Hope it helps.