In C89/C99/C11, in a freestanding environment, the entry point function is implementation-defined. In a hosted environment, it must be int main
in a strictly-conforming program. Most modern compilers make void main
an error. However, I see many users using void main
. Even if it is allowed in a non-conforming compiler, why would one use it? I see no practical reason why void main
would be preferred to int main
. Even in C89, it's undefined behavior to leave off the return
.
Is there a historical reason for the popularity of void main
?
I don't believe my question is primarily opinion-based. Some valid ideas have already been presented in this thread, such as Microsoft's void main
extension, and since Window's popularity, as well as it being the result of C books reprinting incorrect information. These are objective and historical reasons.