5 ms·
No, it's not undefined behavior. An aside: "ANSI C" usually refers to the C language as defined by the last standard directly published by ANSI, in 1989 -- but
by _kst_ 5y ago
No, it's not undefined behavior.
An aside: "ANSI C" usually refers to the C language as defined by the last standard directly published by ANSI, in 1989 -- but the ANSI organization has adopted each new ISO C standard after publication, so the C standard currently recognized by ANSI is ISO C 2017. We're not going to get people to change what they mean by "ANSI C", so I suggest referring instead to "C89" or "C90".
In C90, not returning a value from main() causes an undefined status to be returned to the environment. It does not cause undefined behavior. The behavior of such a program is otherwise well defined. (C99 and later made reaching the closing "}" of the main function do an implicit "return 0;" instead, a rule borrowed from C++.)
- perryizgr8 5y ago> It does not cause undefined behavior. I haven't read the standard. I am just stating what TFA says. So are you saying it is inaccurate?
- _kst_ 5y agoYes, it's inaccurate. Here's what the C90 standard says: 5.1.2.2.3 Program termination A return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument. If the main function executes a return that specifies no value, the termination status returned to the host environment is undefined.