Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Write a C program that does NOT use time! |
| Date | 2016-11-17 09:07 -0800 |
| Organization | None to speak of |
| Message-ID | <lnfumqghly.fsf@kst-u.example.com> (permalink) |
| References | <o0eqoq$t9u$1@dont-email.me> <o0f3e7$qfp$2@dont-email.me> <o0kllu$n53$1@dont-email.me> |
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
> On Tuesday November 15 2016 08:44, in comp.lang.c, "Mr. Man-wai Chang"
> <toylet.toylet@gmail.com> 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 <http://www.ghoti.net/~kst>
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"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Write a C program that does NOT use time! "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-15 19:16 +0800
Re: Write a C program that does NOT use time! Robert Spanjaard <spamtrap@arumes.com> - 2016-11-15 13:30 +0100
Re: Write a C program that does NOT use time! "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-15 21:11 +0800
Re: Write a C program that does NOT use time! "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-16 01:42 +0800
Re: Write a C program that does NOT use time! "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-15 21:44 +0800
Re: Write a C program that does NOT use time! jameskuyper@verizon.net - 2016-11-16 06:52 -0800
Re: Write a C program that does NOT use time! Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-11-17 11:26 -0500
Re: Write a C program that does NOT use time! "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-18 01:00 +0800
Re: Write a C program that does NOT use time! Keith Thompson <kst-u@mib.org> - 2016-11-17 09:07 -0800
Re: Write a C program that does NOT use time! "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-11-15 09:46 -0800
Re: Write a C program that does NOT use time! "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-16 11:46 +0800
Re: Write a C program that does NOT use time! Mark Storkamp <mstorkamp@yahoo.com> - 2016-11-16 08:09 -0600
Re: Write a C program that does NOT use time! "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-16 22:15 +0800
Re: Write a C program that does NOT use time! Mark Storkamp <mstorkamp@yahoo.com> - 2016-11-16 09:05 -0600
Re: Write a C program that does NOT use time! "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-17 22:13 +0800
Re: Write a C program that does NOT use time! "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-11-17 06:21 -0800
Re: Write a C program that does NOT use time! Mark Storkamp <mstorkamp@yahoo.com> - 2016-11-17 09:36 -0600
Re: Write a C program that does NOT use time! "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-11-17 07:45 -0800
Re: Write a C program that does NOT use time! Jerry Stuckle <jstucklex@attglobal.net> - 2016-11-17 11:47 -0500
Re: Write a C program that does NOT use time! "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-18 00:57 +0800
Re: Write a C program that does NOT use time! Robert Wessel <robertwessel2@yahoo.com> - 2016-11-17 20:11 -0600
Re: C on IBM mainframes "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-18 17:30 +0800
Re: C on IBM mainframes Robert Wessel <robertwessel2@yahoo.com> - 2016-11-21 03:19 -0600
Re: C on IBM mainframes "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-21 19:12 +0800
Re: C on IBM mainframes "J. Clarke" <j.clarke.873638@gmail.com> - 2016-12-04 07:40 -0500
Re: C on IBM mainframes "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-12-04 20:57 +0800
Re: Write a C program that does NOT use time! David Brown <david.brown@hesbynett.no> - 2016-11-18 10:32 +0100
csiph-web