Function main() confusion

Hello, There's still a thing that confuse me in C++. Specially in that main() function. This is my question.
Does the real world programs written in C++(million lines of codes), omit the main() function?
Does the real world programs written in C++(million lines of codes), omit the main() function?


No.
May you please explain it to me? I might asking for too much.

I can change the function header into
1
2
float main(){
return 1.00;}

1
2
void main(){
return;}

then compile it without any problems, but why a simple name of the function can't be changed.


Does the main() function is Compulsory name for that function. Its really drives me nut.

then compile it without any problems

Then get a C++ compiler. In C++, main returns an int. That's all. Anything else is not C++. Whatever you're using is not a C++ compiler (let me guess - it's something from 20 years ago?).

The C++ standard (the document that tells you what C++ is) makes it very clear. "A program shall contain a global function called main, which is the designated start of the program".
Last edited on
@asdlkjqweo
Hello, There's still a thing that confuse me in C++. Specially in that main() function. This is my question.
Does the real world programs written in C++(million lines of codes), omit the main() function?


When learn C# instead of C++. There is no main function in C#. There is Main.:)
OP wrote:
Its really drives me nut.

Hello main() hater,

If it really drives you nut, then try this macro trick...
...but at the end, it is still processed as main().

1
2
3
4
5
6
7
8
#include<stdio.h>
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)

int begin()
{
     printf(” hello “);
}


Cooled you down right?
Aceix.
Last edited on
I use Microsoft Visual Studio C++ 2010 Express.
1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;
void main()
{
cout<<"hello!"<<endl;
system("pause");
return;
}


1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;
float main()
{
cout<<"Hello!"<<endl;
system("pause");
return 1.00
}

This program compiles without a hitch.
From that, I am now curious if the C++ Applications available in the market use or didn't use the main()for the designated start of the program; and then you Answered No.

A program shall contain a global function called main, which is the designated start of the program".
From what you answered there, so it means that every C++ program must omit main() function. Sorry if I can't really make my Questions clear,but Thanks for the Answers!
Does the real world programs written in C++(million lines of codes), omit the main() function?

Certainly not: one of the programs at my work here is over 100 MLoC, and it has the main() function, it's the usual int main(int argc, char *argv[]) in a C++ source file.
I use Microsoft Visual Studio C++ 2010 Express.

The MS C++ compiler is well known for allowing non-C++ code.


From what you answered there, so it means that every C++ program must omit main() function.

Did you mean "must NOT omit"?
Topic archived. No new replies allowed.