🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4651

Re: atexit() and return from main()

#4651
From: Nick Maclaren
Date: Wed, 17 Jan 1996 10:17
28 lines
1309 bytes
In article <4dhfja$j50@fg70.rz.uni-karlsruhe.de>, ig25@fg70.rz.uni-karlsruhe.de (Thomas Koenig) writes:
|> Is the following valid C?  [ NMM is to blame for the style! ]
|> 
|> char *a;
|> void printit() { printf("%s",a); }
|> 
|> int main() {
|>     char buffer[]="Hello, world!\n";
|>     a = buffer;
|>     atexit(printit);
|>     return 0;
|> }
|> 
|> 6.1.2.4 tells me it isn't, but 5.1.2.2.3 tells me that a return
|> from the initial call to main() is equivalent to an exit(), and 
|> I don't see a problem when I replace the 'return 0' above with
|> an 'exit(0)'.

I do.  exit() may unwind the stack before calling the atexit()
functions, and that is actually the way that most C run-time
systems implement close down.


Nick Maclaren,
University of Cambridge Computer Laboratory,
New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
Email:  nmm1@cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679
Technical Details
Message-ID: <4diicg$i9e@lyra.csx.cam.ac.uk>
Path: arc1-ca.pugleaf.net!lyra.csx.cam.ac.uk!nmm1
References: <4dhfja$j50@fg70.rz.uni-karlsruhe.de>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!lyra.csx.cam.ac.uk!nmm1
From: nmm1@cus.cam.ac.uk (Nick Maclaren)
Newsgroups: comp.std.c
Subject: Re: atexit() and return from main()
Date: 17 Jan 1996 10:17:52 GMT
Organization: University of Cambridge, England
Message-ID: <4diicg$i9e@lyra.csx.cam.ac.uk>
References: <4dhfja$j50@fg70.rz.uni-karlsruhe.de>
NNTP-Posting-Host: ursa.cus.cam.ac.uk