If C is so evil why is it so successful?

Alfred M. Szmidt ams at gnu.org
Thu Apr 13 01:48:24 CDT 2017


   It was thus said that the Great Alfred M. Szmidt once stated:
   >    It was thus said that the Great Noel Chiappa via cctalk once stated:
   >    >     > From: Alfred M. Szmidt
   >    > 
   >    >     > No even the following program:
   >    >     >   int main (void) { return 0; }
   >    >     > is guaranteed to work
   >    > 
   >    > I'm missing something: why not?
   > 
   >      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; }
   > 
   > Pedantically, it does not matter -- a return from main is equivalent
   > to an exit(), and exit(0) is sensibly defined, and EXIT_SUCCESS can
   > also be different from 0 (even though I don't think such a platform
   > exists).
   > 
   > Similiarly for EXIT_FAILURE ...

     There's this
   (http://stackoverflow.com/questions/8867871/should-i-return-exit-success-or-0-from-main/8868139#8868139):

	   Somebody asked about OpenVMS. I haven't used it in a long time, but
	   as I recall odd status values generally denote success while even
	   values denote failure. The C implementation maps 0 to 1, so that
	   return 0; indicates successful termination. Other values are passed
	   unchanged, so return 1; also indicates successful termination.
	   EXIT_FAILURE would have a non-zero even value.

     And certainly VMS is on topic for this list.

     -spc (So ... pedantically speaking, who's correct?)

The standard, from 7.20.4.3:

  Finally, control is returned to the host environment.  If the value
  of status is zero or EXIT_SUCCESS, an implementation-defined form of
  the status successful termination is returned.  If the value of
  status is EXIT_FAILURE, an implementation-defined form of the status
  unsuccessful termination is returned. Otherwise the status returned
  is implementation-defined.


More information about the cctalk mailing list