Path: utzoo!attcan!uunet!aplcen!samsung!rex!wuarchive!udel!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: (* func)(fred, bert) Message-ID: <11661@smoke.BRL.MIL> Date: 21 Nov 89 22:38:54 GMT References: <2387@stl.stc.co.uk> <744@lakart.UUCP> <0175@sheol.UUCP> <812@bbm.UUCP> <11592@smoke.BRL.MIL> <374@helens.Stanford.EDU> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 37 In article <374@helens.Stanford.EDU> mike@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 or some local equivalent in non-Standard C environments, to assure portability.) Minimal correct "Hello" program: #include main() { printf( "Hello, world!\n" ); return 0; } Similar program showing both success and failure termination status: #include #ifdef __STDC__ #include /* 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 */ }