Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Write a C program that does NOT use time! Date: Thu, 17 Nov 2016 09:07:37 -0800 Organization: None to speak of Lines: 45 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="9e5c6cdd6c882157dc720953c941e742"; logging-data="26897"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+TB7SGKTDsQ3i01yiK57/c" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:2qC1oKsZP9m53j89QSFWCx0uXtQ= sha1:lY/gMI1JloIGqC/DPiAoQ8pdf9w= Xref: csiph.com comp.lang.c:96753 Lew Pitcher writes: > On Tuesday November 15 2016 08:44, in comp.lang.c, "Mr. Man-wai Chang" > wrote: [...] >> void main() { > > 3) int main(void) { > >> exit(0); > > 4) if main() function is defined as void main(), then > exit(0); > is (IMHO) superfluous [...] For hosted implementations, there is of course no good reason to use void main() or void main(void). But implementations are permitted to permit it. If the main function is properly defined as `int main(void)`, then `exit(0)` is superfluous; reaching the closing `}` does an implicit `return 0;`. This rule was added in C99, so either `exit(0);` or `return 0;` might be needed if your code might be compiled with a pre-C99 or otherwise non-conforming compiler (or if the exit or return appears other than at the very end of main()). "If the return type is not compatible with int, the termination status returned to the host environment is unspecified." (N1570 5.1.2.2.3), so if you use `void main()` *and* the implementation permits it, `exit(0)` might be required (and `return 0;` would be invalid). Another very real possibility is that an implementation could permit (fail to diagnose) `void main(void)`, but not document its behavior. In that case, the behavior is undefined. For freestanding implementations, the name and type of the entry point are implementation-defined. If the implementation says you have to use `void mane(void)`, that's what you have to use. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"