Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #161493
| Path | csiph.com!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!3.eu.feeder.erje.net!feeder.erje.net!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
| Newsgroups | comp.lang.c |
| Subject | Re: Calling exit in main |
| Date | Fri, 25 Jun 2021 01:34:54 -0700 |
| Organization | None to speak of |
| Lines | 31 |
| Message-ID | <87im22uytt.fsf@nosuchdomain.example.com> (permalink) |
| References | <sb3sbt$j9a$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | reader02.eternal-september.org; posting-host="e76a60976a03f7b22ccc859f0f74fb19"; logging-data="6434"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+0SYQrXchvFIIEjE/xEPO/" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
| Cancel-Lock | sha1:w/ThTK3Edc09yXDn0iX+vHkSPbQ= sha1:PtxrsFjm67ea1+TnGYW6N//zIO4= |
| Xref | csiph.com comp.lang.c:161493 |
Show key headers only | View raw
Mehdi Amini <atorrses@gmail.com> writes:
> I looked at some code on the Internet similar to this:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(void)
> {
> printf("Calling exit in main\n");
> exit (0);
> }
>
> Both gcc and clang issue no diagnostic about it. Do you think it is
> proper to use exit instead of return in main ?
Sure, why not? exit(0) is (very nearly) equivalent to return 0 in main.
(There are some subtle differences involving the atexit() function, but
they don't apply here.)
Or you can just omit it, since reaching the end of main implicitly
returns a value of 0 (in C99 or later).
Returning a value of 0, either via a return statement or by passing it
to exit, returns a value indicating success. You can indicate failure
by returning EXIT_FAILURE, also via either "exit(EXIT_FAILURE);" or
"return EXIT_FAILURE;".
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Calling exit in main Mehdi Amini <atorrses@gmail.com> - 2021-06-25 10:46 +0430
Re: Calling exit in main Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> - 2021-06-25 08:19 +0200
Re: Calling exit in main Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-06-25 00:48 -0700
Re: Calling exit in main Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> - 2021-06-25 10:08 +0200
Re: Calling exit in main Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-06-25 01:38 -0700
Re: Calling exit in main Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> - 2021-06-25 11:03 +0200
Re: Calling exit in main Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-06-25 08:27 -0700
Re: Calling exit in main Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> - 2021-06-25 18:52 +0200
Re: Calling exit in main Kaz Kylheku <563-365-8930@kylheku.com> - 2021-06-25 17:14 +0000
Re: Calling exit in main scott@slp53.sl.home (Scott Lurndal) - 2021-06-25 18:17 +0000
Re: Calling exit in main Kaz Kylheku <563-365-8930@kylheku.com> - 2021-06-25 18:48 +0000
Re: Calling exit in main Real Troll <real.troll@trolls.com> - 2021-06-25 20:21 +0100
Re: Calling exit in main Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> - 2021-06-26 09:21 +0200
Re: Calling exit in main Kaz Kylheku <563-365-8930@kylheku.com> - 2021-06-28 16:45 +0000
Re: Calling exit in main Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-06-28 18:14 +0100
Re: Calling exit in main Richard Damon <Richard@Damon-Family.org> - 2021-06-25 13:33 -0400
Re: Calling exit in main Kaz Kylheku <563-365-8930@kylheku.com> - 2021-06-25 15:05 +0000
Re: Calling exit in main Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-06-25 01:34 -0700
Re: Calling exit in main James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-06-25 11:51 -0400
Re: Calling exit in main Kaz Kylheku <563-365-8930@kylheku.com> - 2021-06-25 16:13 +0000
Re: Calling exit in main Guillaume <message@bottle.org> - 2021-06-25 18:48 +0200
Re: Calling exit in main Kaz Kylheku <563-365-8930@kylheku.com> - 2021-06-25 17:05 +0000
Re: Calling exit in main Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2021-06-25 15:22 -0600
Re: Calling exit in main Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2021-06-25 15:29 -0600
Re: Calling exit in main James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-06-25 14:50 -0400
Re: Calling exit in main James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-06-25 14:59 -0400
Re: Calling exit in main Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-06-25 13:40 -0700
Re: Calling exit in main Jens Schweikhardt <usenet@schweikhardt.net> - 2021-06-26 08:25 +0000
Re: Calling exit in main Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-06-25 10:42 -0700
Re: Calling exit in main James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-06-25 14:51 -0400
csiph-web