Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Calling exit in main Date: Fri, 25 Jun 2021 01:38:27 -0700 Organization: None to speak of Lines: 35 Message-ID: <87eecquynw.fsf@nosuchdomain.example.com> References: <87mtrev0yd.fsf@nosuchdomain.example.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="e76a60976a03f7b22ccc859f0f74fb19"; logging-data="6434"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+EusRV9TgIzUANsjBqbrme" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:TJnFau6O10hEo7kdY7p5exYC5W4= sha1:ha2JSagsmr1jx/L/drI0K4GjJGw= Xref: csiph.com comp.lang.c:161494 Kli-Kla-Klawitter writes: > Am 25.06.2021 um 09:48 schrieb Keith Thompson: >> Kli-Kla-Klawitter writes: >>> Am 25.06.2021 um 08:16 schrieb Mehdi Amini: >>>> I looked at some code on the Internet similar to this: >>>> #include >>>> #include >>>> 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 ? >>> >>> There's a race-condition here: >>> will the program crash sooner than it exit()s? >> There is no race condition. Why do you think the program would >> crash? >> > exit() could be earlier called than the stout-buffers are flushed!!!!! exit() causes all buffers to be flushed. N1570 7.22.4.4 paragraph 4 (describing the exit function): Next, all open streams with unwritten buffered data are flushed, all open streams are closed, and all files created by the tmpfile function are removed. Paragraph 5: Finally, control is returned to the host environment. ... -- 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 */