On Wed, Apr 12, 2017 at 9:55 AM, Sean Conner via cctalk < cctalk@classiccmp.org> wrote:
> Yeah, I'm having a hard time with that too. I mean, pedantically, it > should be: > > #include <stdlib.h> > int main(void) { return EXIT_SUCCESS; } > > where EXIT_SUCCESS is 0 on every plaform except for some obscure system no > one has heard of but managed to influence the C committee back in the late > 80s. > Returning zero from main to indicate success is perfectly valid according to the most recent three C standards. ISO/IEC 9899:1990(E) §7.10.4.3, ISO/IEC 9899:1999(E) §7.20.4.3 ¶5 and ISO/IEC 9899:2011(E) §7.22.4.4 ¶5 both requires that either 0 or EXIT_SUCCESS as an argument to exit() be considered success. EXIT_SUCCESS may or may not be zero, but zero is considered success regardless of that. One annoyance with the way the standard defines the EXIT_x macros is that if you use other exit status values, including those from sysexits.h (not part of the C standard), it's possible that an intended failure status value might happen to match EXIT_SUCCESS on some standard-compliant implementation. §5.1.2.2.3 ¶1 of both :1999 and :2011 state that if execution reaches the closing brace of main without a return statement, that it is equivalent to returning zero, so even the return statement in this alleged non-portable example is unnecessary. On the other hand, the earlier ISO/IEC 9899:1990(E) §5.1.2.2.3 says that main returning with no value yields an undefined termination status. -- Eric "not a language lawyer but I play one on the internet" Smith