Show: Object Pascal C++
Display Preferences

About The main() Function

From Appmethod Topics
Jump to: navigation, search

Go Up to The main() Function Index

Every C and C++ program must have a program-startup function:

  • Console-based programs call the main function at startup and the wmain function for UNICODE programs.
  • Windows GUI programs call the WinMain function at startup and the wWinMain function for UNICODE programs.

Where you place the startup function is a matter of preference. Some programmers place main at the beginning of the file, others at the end. Regardless of its location, the following points about main always apply:

Our Clang-enhanced C++ Compilers (BCC64, BCCIOSARM, and BCCAARM) now enforce the requirement that declarations have a type in C++. So, for example, you now receive an error if WinMain has no return type, as in:

WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
  ...
}

The above now generates the following error:

C++ requires a type specifier for all declarations

To remedy this error, update the code to read:

int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
  ...
}
Personal tools
In other languages