🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4732

Re: atexit() and return from main()

#4732
From: Tanmoy Bhattacharya
Date: Wed, 31 Jan 1996 21:27
36 lines
2358 bytes
In article <4emq9l$2fn@hammy.lonestar.org> gordon@hammy.lonestar.org
(Gordon Burditt) writes: 
<snip>
   ANSI C Classic 2.1.2.2.3 Program Termination
   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.
   ...
   I claim that longjmp()ing out of an atexit function into main
   causes undefined behavior because main() has already returned
   (or, equivalently, called exit()) between the setjmp and
   longjmp calls.

   In fact, calling exit() may not unwind the stack like returning
   from main() does, so you might get away with it, but there's
   no guarantee.

Isn't the TC going to clarify that return from main is not exactly the
same as calling exit? Or is it just planning to restrict the
clarification to the situation with respect to the local variables?

In any case, without a change in the standard, I would consider that
the wording in the standard is that `a return ... is equivalent to
calling the exit function...' not the other way round. So, I would
interpret this as saying that return from main cannot unwind stack
either, exactly as exit cannot: not that both can.

Cheers
Tanmoy
--
tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
Technical Details
Message-ID: <TANMOY.96Jan31142738@qcd.lanl.gov>
Path: arc1-ca.pugleaf.net!newshost.lanl.gov!tanmoy
References: <4dhfja$j50@fg70.rz.uni-karlsruhe.de> <4diicg$i9e@lyra.csx.cam.ac.uk> <TANMOY.96Jan22084309@qcd.lanl.gov> <DLMLL6.A0H@ukpsshp1.serigate.philips.nl> <4emq9l$2fn@hammy.lonestar.org>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newshost.lanl.gov!tanmoy
From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
Newsgroups: comp.std.c
Subject: Re: atexit() and return from main()
Date: 31 Jan 1996 21:27:38 GMT
Organization: Los Alamos National Laboratory
Message-ID: <TANMOY.96Jan31142738@qcd.lanl.gov>
References: <4dhfja$j50@fg70.rz.uni-karlsruhe.de> <4diicg$i9e@lyra.csx.cam.ac.uk>
 <TANMOY.96Jan22084309@qcd.lanl.gov>
 <DLMLL6.A0H@ukpsshp1.serigate.philips.nl>
 <4emq9l$2fn@hammy.lonestar.org>
NNTP-Posting-Host: qcd.lanl.gov
Mime-Version: 1.0
Content-Type: text
In-reply-to: gordon@hammy.lonestar.org's message of 30 Jan 1996 22:13:41 -0600