CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: main function

  1. #1
    Join Date
    Apr 2001
    Posts
    33

    main function

    who calls the main function?

  2. #2
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,020
    It varies from system to system. Set a breakpoint at the first instruction in main and have a look at the stack trace.
    Succinct is verbose for terse

  3. #3
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443
    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:
    Code:
    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.
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.

  4. #4
    Join Date
    Apr 2000
    Location
    Frederick, Maryland
    Posts
    507
    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.

    Code:
    #pragma comment(linker, "/ENTRY:Zee")
    
    int _stdcall Zee()
    {
    	return 0;
    }
    Hope it helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured