Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ No main() function?

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?

like image 333
John Tilley Avatar asked Jul 12 '11 10:07

John Tilley


People also ask

Is it possible to write a C program without main () function?

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.

What is a main () function in C?

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.

Does a program have to have a main function?

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?

How to call all predefined and user-defined functions in C?

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.


1 Answers

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...

like image 161
bert-jan Avatar answered Oct 07 '22 22:10

bert-jan