Every C++ books that I’ve read says something like this:-
- All C++ programs have a main() function.
- main() function is the starting point for all C++ programs.
- All C++ programs begin its execution from the main() function.
However, I found that Windows programs written using MFC do not have any main() function. It use WinMain() function as the program starting point.
So can I say that Windows program written using MFC is not a C++ program? Then, what kind of program it is?
Thanks.
The answer to this question is a little more complicated than yes or no. It depends largely, on how strict you make your definition of “C++ program”. A Windows subsystem program built with MSVC will not generally have a
mainfunction. MFC is a C++ language framework for building Windows subsystem programs (at least in contemporary practice). For the purposes of “Is a program written without a main function using a C++ compiler a C++ program, and if not, what is it?” MFC is irrelevant.The
mainfunction, can be talked about in terms of “freestanding” and “hosted” implementations. Only “hosted” implementations are required by the standard to have main as an entry point. That said, you’d be hard pressed to call Microsoft’s implementation of the CRT and the language “freestanding” with a straight face.So we could make the question more specific “Is an MFC application a conforming, hosted C++ program?” and the answer to that would be “Technically, very technically, no.”
Re: freestanding vs. hosted:
Any run of the mill C++ user land application is generally going to be hosted, that is have the benefit of the standard library et. al. Examples of freestanding scenarios might in an embedded system or an operating system kernel. For example when writing an OS kernel you can’t rely on the presence of functionality like malloc or new because you’re implementing the services (virtual memory, processes, etc.) that will ultimately used to implement things like malloc and new.