(* func)(fred, bert)
Doug Gwyn
gwyn at smoke.BRL.MIL
Wed Nov 22 09:38:54 AEST 1989
In article <374 at helens.Stanford.EDU> mike at relgyro.STANFORD.EDU (Mike Macgirvin) writes:
> I realize what the compiler is complaining about, but the solution
>seems to be bad coding practice. (My Unix compiler will cough on the above
>with a 'Statement not reached' warning...).
Better solutions are possible. Since, so far as I am aware, implementations
that do not honor the value returned by main() always report "success" when
main() is returned from, "return 0" from main() is just as good as "exit(0)"
and has the added merit of shutting up "lint" (or some equivalent compiler
warning). For "return n" (n != 0), you probably ought to use "exit(n)"
instead, just to make sure that the error status reaches the environment.
(For n, you should use EXIT_FAILURE from <stdlib.h> or some local equivalent
in non-Standard C environments, to assure portability.)
Minimal correct "Hello" program:
#include <stdio.h>
main() {
printf( "Hello, world!\n" );
return 0;
}
Similar program showing both success and failure termination status:
#include <stdio.h>
#ifdef __STDC__
#include <stdlib.h> /* for EXIT_FAILURE */
#else
#include "mydefs.h" /* for EXIT_FAILURE */
#endif
main() {
if ( getchar() != EOF )
printf( "Thanks, I needed that!\n" );
else
exit( EXIT_FAILURE );
return 0; /* or EXIT_SUCCESS */
}
More information about the Comp.lang.c
mailing list