Home cannot be invalid

Possible duplicate:
does the C ++ standard prohibit the void main () prototype?

Why is C ++ not allowing me to do void main()? This is not a big problem, but I'm still interested.

+5
source share
4 answers

Since the return type main()(as specified in the standard) should beint

C ++ 03 [ Section 3.6.1Main Function]

Implementation should not predetermine the main function. This function should not be overloaded. It must have a return type of int , but otherwise its type is determined by the implementation.

+11
source

Stroustrup:

"void main()" ?

void main() { /* ... */ }

++, C. . ISO ++ 3.6.1 [2] ISO C 5.1.2.2.1.

int main() { /* ... */ }

int main(int argc, char* argv[]) { /* ... */ }

main(), int. int, main(), "", . , , , "void main()" ++ C. "void main()" , C ++.

++ main() return. 0, . :

#include<iostream>

int main()
{
    std::cout << "This program returns the integer value 0\n";
}

, ISO ++, C99 . , C89 ARM ++, "int" , . :

#include<iostream>

main() { /* ... */ }

, main().

: http://www2.research.att.com/~bs/bs_faq2.html#void-main

+9

, int.

+4

Some operating systems expect integral process return values. Declare main to return int. If you don't care about the value, just return 0.

From the frequently asked questions about comp.lang.c:

+1
source

All Articles