C ++ why main works without return value

This question is out of curiosity; when writing the main one for the test program, I did not return anything from main(no returnstatement in main). But I called main int main(). And it compiled successfully.

If, as if some other function was written with a return type intand did not actually return int, I would get an error

"Function Name" should return a value

So why does the compiler not complain about the function main?

+4
source share
2 answers

-void-, -. main -, .

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2960.pdf:

§ 3.6.1/5

, , 0;

, , . - , .

+7

++, int main() , 0.

5.1.2.2.3

1 , int, , ; 11) }, 0. int, , , .

EXIT_SUCCESS EXIT_FAILURE main().

int, (Windows) (0-255). Unix , , . , EXIT_SUCCESS EXIT_FAILURE

GNU

-POSIX- . EXIT_SUCCESS EXIT_FAILURE , . stdlib.h.

- : int EXIT_SUCCESS .

POSIX 0. - (, ) .

- : int EXIT_FAILURE .

POSIX 1. - (, ) . . , "". , diff 1, , , 2 , .

+1

All Articles