0

Hello!

I have a sample application. I just put a breakpoint at the beginning of main(). The callstack pointed to a function called mainCRTStartup() and before that, the kernel32.dll was present(grayed out). Can anyone please tell me what these functions are, and who invokes them?

Thanks in advance!

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by deceptikon
1

The C++ runtime eventually has to call your main(), but there's stuff that needs to be done both before and after. Judging by the name, you're using a Microsoft compiler. If you have the CRT sources then look for crt0.c, it's a small source file that does the runtime initialization.

0

So, if i get this correct, the kernel invokes the MSVCRT(i'm using a MS compiler) which in-turn invokes the main(). Am i correct?

1

It's probably safer to say that there's hidden initialization and termination code in your program's executable. While it's correct to say that main() is the starting point for a program, it's not necessarily the first starting point. When your executable is loaded into memory, the starting address is probably at mainCRTStartup() instead of main().

Votes + Comments
Thanks!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.