Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #161489 > unrolled thread

Calling exit in main

Started byMehdi Amini <atorrses@gmail.com>
First post2021-06-25 10:46 +0430
Last post2021-06-25 14:51 -0400
Articles 20 on this page of 30 — 13 participants

Back to article view | Back to comp.lang.c


Contents

  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

Page 1 of 2  [1] 2  Next page →


#161489 — Calling exit in main

FromMehdi Amini <atorrses@gmail.com>
Date2021-06-25 10:46 +0430
SubjectCalling exit in main
Message-ID<sb3sbt$j9a$1@dont-email.me>
Hi,

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 ?

[toc] | [next] | [standalone]


#161490

FromKli-Kla-Klawitter <kliklaklawitter69@gmail.com>
Date2021-06-25 08:19 +0200
Message-ID<sb3sh5$6g2$1@gioia.aioe.org>
In reply to#161489
Am 25.06.2021 um 08:16 schrieb Mehdi Amini:
> Hi,
> 
> 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 ?

There's a race-condition here:
will the program crash sooner than it exit()s?

[toc] | [prev] | [next] | [standalone]


#161491

FromKeith Thompson <Keith.S.Thompson+u@gmail.com>
Date2021-06-25 00:48 -0700
Message-ID<87mtrev0yd.fsf@nosuchdomain.example.com>
In reply to#161490
Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> writes:
> Am 25.06.2021 um 08:16 schrieb Mehdi Amini:
>> 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 ?
>
> 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?

-- 
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 */

[toc] | [prev] | [next] | [standalone]


#161492

FromKli-Kla-Klawitter <kliklaklawitter69@gmail.com>
Date2021-06-25 10:08 +0200
Message-ID<sb42tl$rgh$1@gioia.aioe.org>
In reply to#161491
Am 25.06.2021 um 09:48 schrieb Keith Thompson:
> Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> writes:
>> Am 25.06.2021 um 08:16 schrieb Mehdi Amini:
>>> 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 ?
>>
>> 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!!!!!

[toc] | [prev] | [next] | [standalone]


#161494

FromKeith Thompson <Keith.S.Thompson+u@gmail.com>
Date2021-06-25 01:38 -0700
Message-ID<87eecquynw.fsf@nosuchdomain.example.com>
In reply to#161492
Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> writes:
> Am 25.06.2021 um 09:48 schrieb Keith Thompson:
>> Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> writes:
>>> Am 25.06.2021 um 08:16 schrieb Mehdi Amini:
>>>> 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 ?
>>>
>>> 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 */

[toc] | [prev] | [next] | [standalone]


#161495

FromKli-Kla-Klawitter <kliklaklawitter69@gmail.com>
Date2021-06-25 11:03 +0200
Message-ID<sb4645$abl$1@gioia.aioe.org>
In reply to#161494
Am 25.06.2021 um 10:38 schrieb Keith Thompson:
> Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> writes:
>> Am 25.06.2021 um 09:48 schrieb Keith Thompson:
>>> Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> writes:
>>>> Am 25.06.2021 um 08:16 schrieb Mehdi Amini:
>>>>> 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 ?
>>>>
>>>> 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.

Yes, but printf() could be faster.

> 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. ...
> 

[toc] | [prev] | [next] | [standalone]


#161497

FromKeith Thompson <Keith.S.Thompson+u@gmail.com>
Date2021-06-25 08:27 -0700
Message-ID<87wnqit15r.fsf@nosuchdomain.example.com>
In reply to#161495
Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> writes:
> Am 25.06.2021 um 10:38 schrieb Keith Thompson:
>> Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> writes:
>>> Am 25.06.2021 um 09:48 schrieb Keith Thompson:
>>>> Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> writes:
>>>>> Am 25.06.2021 um 08:16 schrieb Mehdi Amini:
>>>>>> 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 ?
>>>>>
>>>>> 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.
>
> Yes, but printf() could be faster.

Faster than what?

After the printf call returns, the data has at least been written to
buffers.  The exit call causes those buffers to be flushed.  There is no
race condition.

If you call _Exit() rather than exit(), the problems you're concerned
about could occur.

>> 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 */

[toc] | [prev] | [next] | [standalone]


#161501

FromKli-Kla-Klawitter <kliklaklawitter69@gmail.com>
Date2021-06-25 18:52 +0200
Message-ID<sb51jo$1k4g$1@gioia.aioe.org>
In reply to#161497
Am 25.06.2021 um 17:27 schrieb Keith Thompson:
> Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> writes:
>> Am 25.06.2021 um 10:38 schrieb Keith Thompson:
>>> Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> writes:
>>>> Am 25.06.2021 um 09:48 schrieb Keith Thompson:
>>>>> Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> writes:
>>>>>> Am 25.06.2021 um 08:16 schrieb Mehdi Amini:
>>>>>>> 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 ?
>>>>>>
>>>>>> 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.
>>
>> Yes, but printf() could be faster.
> 
> Faster than what?

printf() flushes asynchronously in its own thread on some OSs.

> 
> After the printf call returns, the data has at least been written to
> buffers.  The exit call causes those buffers to be flushed.  There is no
> race condition.
> 
> If you call _Exit() rather than exit(), the problems you're concerned
> about could occur.
> 
>>> 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. ...
> 

[toc] | [prev] | [next] | [standalone]


#161504

FromKaz Kylheku <563-365-8930@kylheku.com>
Date2021-06-25 17:14 +0000
Message-ID<20210625100530.656@kylheku.com>
In reply to#161501
On 2021-06-25, Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> wrote:
> printf() flushes asynchronously in its own thread on some OSs.

Can you name one?

(Since your plural "OSs" asserts there are two or more, feel free to
mention others.)

[toc] | [prev] | [next] | [standalone]


#161507

Fromscott@slp53.sl.home (Scott Lurndal)
Date2021-06-25 18:17 +0000
Message-ID<r5pBI.20802$9q1.5557@fx09.iad>
In reply to#161504
Kaz Kylheku <563-365-8930@kylheku.com> writes:
>On 2021-06-25, Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> wrote:
>> printf() flushes asynchronously in its own thread on some OSs.
>
>Can you name one?

Not particularly likely.   kli-kla sounds suspiciously like
Bonita, and even posts using a German locale.

[toc] | [prev] | [next] | [standalone]


#161508

FromKaz Kylheku <563-365-8930@kylheku.com>
Date2021-06-25 18:48 +0000
Message-ID<20210625114442.323@kylheku.com>
In reply to#161507
On 2021-06-25, Scott Lurndal <scott@slp53.sl.home> wrote:
> Kaz Kylheku <563-365-8930@kylheku.com> writes:
>>On 2021-06-25, Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> wrote:
>>> printf() flushes asynchronously in its own thread on some OSs.
>>
>>Can you name one?
>
> Not particularly likely.   kli-kla sounds suspiciously like
> Bonita, and even posts using a German locale.

The Bonita identity is often able to justify its statements with facts; just
the interpretation or significance of the facts is distorted and exaggerated,
and trotted out primarily as a pretext for personal attacks.

Note also that Kli-Kla doesn't trim attributions from quoted material.

[toc] | [prev] | [next] | [standalone]


#161512

FromReal Troll <real.troll@trolls.com>
Date2021-06-25 20:21 +0100
Message-ID<sb5afm$1jj6$1@gioia.aioe.org>
In reply to#161507
On 25/06/2021 19:17, Scott Lurndal wrote:
> Not particularly likely.   kli-kla sounds suspiciously like
> Bonita, and even posts using a German locale.
>
It is silly to accuse people on these public newsgroups without any 
evidence.  No wonder we don't get new users here because of people like 
you here.



[toc] | [prev] | [next] | [standalone]


#161517

FromKli-Kla-Klawitter <kliklaklawitter69@gmail.com>
Date2021-06-26 09:21 +0200
Message-ID<sb6khn$1gbo$1@gioia.aioe.org>
In reply to#161504
Am 25.06.2021 um 19:14 schrieb Kaz Kylheku:
> On 2021-06-25, Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> wrote:
>> printf() flushes asynchronously in its own thread on some OSs.
> 
> Can you name one?

Windows before Win10, some Linux-distrubutions with newer glibcs.

> 
> (Since your plural "OSs" asserts there are two or more, feel free to
> mention others.)
> 

[toc] | [prev] | [next] | [standalone]


#161528

FromKaz Kylheku <563-365-8930@kylheku.com>
Date2021-06-28 16:45 +0000
Message-ID<20210628093146.219@kylheku.com>
In reply to#161517
On 2021-06-26, Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> wrote:
> Am 25.06.2021 um 19:14 schrieb Kaz Kylheku:
>> On 2021-06-25, Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> wrote:
>>> printf() flushes asynchronously in its own thread on some OSs.
>> 
>> Can you name one?
>
> Windows before Win10, some Linux-distrubutions with newer glibcs.

You're now just making shit up.

Windows doesn't have a printf function that is documented for
applications. C compilers for Windows must provide a printf in their
run-time support library.

(There is a library in the system folder called MSVCRT.DLL or something
like that. Using this is like sticking a fork in the toaster;
it is not documented for use by non-Microsoft applications.
It is not offered as part of a C implementation at all, let alone as
a conforming library part of a C implementation. Therefore, I will
not discuss it further.)

Both versions of the program, with the return 0 from main or exit(0)
can be fully expected to have externally indistinguishable behavior
on every version of glibc from the past 20 years.
(Which would be the case even if glibc had a separate thread for
flushing stdio buffers; it positively does not).

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

[toc] | [prev] | [next] | [standalone]


#161529

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2021-06-28 18:14 +0100
Message-ID<87im1xlxmi.fsf@bsb.me.uk>
In reply to#161528
Kaz Kylheku <563-365-8930@kylheku.com> writes:

> On 2021-06-26, Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> wrote:
>> Am 25.06.2021 um 19:14 schrieb Kaz Kylheku:
>>> On 2021-06-25, Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> wrote:
>>>> printf() flushes asynchronously in its own thread on some OSs.
>>> 
>>> Can you name one?
>>
>> Windows before Win10, some Linux-distrubutions with newer glibcs.
>
> You're now just making shit up.

Yup.  I'm pretty sure this is a same poster that did this sort of
trolling a couple of months ago.  They know enough to sound all
technical, and they threw a few threads off course with
confident-sounding junk like this.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#161505

FromRichard Damon <Richard@Damon-Family.org>
Date2021-06-25 13:33 -0400
Message-ID<6soBI.264$al1.178@fx26.iad>
In reply to#161501
On 6/25/21 12:52 PM, Kli-Kla-Klawitter wrote:
> 
> printf() flushes asynchronously in its own thread on some OSs.

If an implementation does this, then it is the implementations
responsibility to get it right. The program given had no 'threads' so
doesn't need to worry about threads.

[toc] | [prev] | [next] | [standalone]


#161496

FromKaz Kylheku <563-365-8930@kylheku.com>
Date2021-06-25 15:05 +0000
Message-ID<20210625080452.768@kylheku.com>
In reply to#161490
On 2021-06-25, Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> wrote:
> Am 25.06.2021 um 08:16 schrieb Mehdi Amini:
>> Hi,
>> 
>> 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 ?
>
> There's a race-condition here:
> will the program crash sooner than it exit()s?

Trolling is not supposed to be that dumb.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

[toc] | [prev] | [next] | [standalone]


#161493

FromKeith Thompson <Keith.S.Thompson+u@gmail.com>
Date2021-06-25 01:34 -0700
Message-ID<87im22uytt.fsf@nosuchdomain.example.com>
In reply to#161489
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 */

[toc] | [prev] | [next] | [standalone]


#161498

FromJames Kuyper <jameskuyper@alumni.caltech.edu>
Date2021-06-25 11:51 -0400
Message-ID<sb4u2n$cls$1@dont-email.me>
In reply to#161489
On 6/25/21 2:16 AM, Mehdi Amini wrote:
> Hi,
> 
> 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 ?

I think "return 0;" is conceptually simpler, but keep in mind that

"a return from the initial call to the main function is equivalent to
calling the exit function with the value returned by the main function
as its argument;" (5.1.2.2.3)

Therefore, the net effect is almost the same. If you had atexit()
handlers that referred to objects with automatic storage duration
declared in main(), then calling exit() rather than returning 0 would be
necessary in order for those handlers to have defined behavior, but
otherwise the effects are pretty much the same.

[toc] | [prev] | [next] | [standalone]


#161499

FromKaz Kylheku <563-365-8930@kylheku.com>
Date2021-06-25 16:13 +0000
Message-ID<20210625090908.588@kylheku.com>
In reply to#161498
On 2021-06-25, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
> Therefore, the net effect is almost the same. If you had atexit()
> handlers that referred to objects with automatic storage duration
> declared in main(), then calling exit() rather than returning 0 would be
> necessary in order for those handlers to have defined behavior, but
> otherwise the effects are pretty much the same.

Here is another way of referring to automatic storage in main
at exit time:

  int main()
  {
    char buf[16*BUFSIZ];

    setvbuf(stdout, buf, _IOFBF, sizeof buf);
    printf("hello");

    /* return 0; bad! */
    exit(0);
  }

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.c


csiph-web