I'm a graduate programmer and when it comes to C++ I expect there to be a main()
function everytime.
However I've been given a project written in C++ with Visual Studio 6.0 and it doesn't have a main()
function. I really can't figure out how this program executes or where it begins.
I have seen examples of the Macro that can be used to change the name of the main()
function, however this code shows no sign of that practice.
Can anyone suggest what I should be looking for?
Logically it’s impossible to write a C program without main () function. It’s true that a C program can’t be written without main () function. There are some methods given below, but truth is that in every method, main () function is hidden or used in an indirect way. Now, look at some examples given below.
A C program starts with a main () function, usually kept in a file named main.c. This program compiles but doesn't do anything. Correct and boring.
Although the standard states that program must have a main function, this does not have to written by the application developer if the libraries that are linked to have the main function defined in them. Also, some linkers allow you to redefine the entry point to something other than main. Is there a WinMain at all?
All Predefined and User-defined Functions are called directly or indirectly through the main. Therefore we will use preprocessor (a program which processes the source code before compilation) directive #define with arguments to give an impression that the program runs without main.
Maybe the main function is in a library, and the program startes with a virtual function call on a static object. That's what happens in MFC-applications.
The program derives a class from CWinApp and instanciates it once as a static variable. MFC then knows a pointer (that was set up by the constructor of CWinApp, and calls the virtual function InitInstance() on that pointer.
See, here's where the software from the program takes over...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With