Some incorrect answers here. First, to counter what others have said:
@Sandeep:
Try writing a windows app. Why is there no main?
@Apoorlone:
Include files don't get compiled. Libraries are compiled already.
@Balabek:
"Operating systems don't always call this function, it actually depends on platform, hence there is not always need for you to implement it."
Except C and C++ are portable...
"All Windows programs have that [WinMain()]"
Nope. Only the ones that write a Windows GUI program. You can write a console app without WinMain.
"But when writing a console program for Windows, static linking libraries that implement WinMain() will be provided"
Wrong again. What libraries are these? Are you talking about the C and C++ runtime libraries? Take a look at the compiler code for gcc, or read up on implementation. You'll see that WinMain() is *not* called for a console program.
"Try writing a console program without a main() call, and you'll see a linker error that says function definition is not defined."
Yeah because mainCRTSTartup calls main(), but main() doesn't exist. Try dropping standard libs with compiler flags, and you'll see it complain about mainCRTStartup instead of main().
"all initalization before calling main() and all cleanup after main() function returns are handled automatically."
Unless you take over that part. In which case you don't need main.
Yes, you can write a C program without main().
- You aren't writing a console program. Dlls, static libraries, Windows programs qualify.
- You redefined the entry point through compiler options.
- You dropped standard compiler libraries, so now you have to implement mainCRTStartup yourself.