Article View: comp.std.c
Article #4653Re: atexit() and return from main()
From: Mark Brader
Date: Wed, 17 Jan 1996 10:59
Date: Wed, 17 Jan 1996 10:59
29 lines
1778 bytes
1778 bytes
Thomas.Koenig@ciw.uni-karlsruhe.de writes:
/* code compressed and excerpted --msb */
> char *a;
> void printit()
> { printf("%s",a); }
> int main()
> { char buffer[]="Hello\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 think that a strict reading of the existing standard requires 5.1.2.2.3
to take precedence (it gives the return special semantics, so it doesn't
really cause the block containing it to be exited from), thus making the
code legal. However, clearly this was not intended and would be burdensome
to implementers, and I'd expect the code to fail in real life; and it's
probably possible to read it the other way anyway.
Defect Report 85 raised this issue and suggested resolving it by explicitly
giving 6.1.2.4 precedence, so that the code would cause undefined behavior.
According to the item posted recently about Technical Corrigendum 2, this
change was accepted and will be officially published soon.
--
Mark Brader "Should array indices start at 0 or 1? My ecumenical
msb@sq.com compromise of 0.5 was rejected without, I thought,
SoftQuad Inc., Toronto proper consideration." -- Stan Kelly-Bootle
My text in this article is in the public domain.
Technical Details
Message-ID:
<1996Jan17.105929.7146@sq.com>Path:
arc1-ca.pugleaf.net!howland.reston.ans.net!torn!sq!msbReferences:
<4dhfja$j50@fg70.rz.uni-karlsruhe.de>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!howland.reston.ans.net!torn!sq!msb From: msb@sq.com (Mark Brader) Subject: Re: atexit() and return from main() Message-ID: <1996Jan17.105929.7146@sq.com> Organization: SoftQuad Inc., Toronto, Canada References: <4dhfja$j50@fg70.rz.uni-karlsruhe.de> Date: Wed, 17 Jan 1996 10:59:29 GMT