Topic: Calling exit() from the dtor of a static object
Author: simon@sco.COM (Simon Tooke)
Date: 1995/10/25 Raw View
In <951024.195404z.11077.das@lanai.cs.ucla.edu> David A Smallberg <das@CS.UCLA.EDU> writes:
>Although I know what some implementations do, I can't determine from
>the Working Paper what should happen in this case:
> int n = 0;
> struct X {
> ~X() { exit(++n); }
> };
> X a;
> X b;
> int main()
> {
> exit(n);
> }
>Does the destructor for "a" get called? Is the exit status 0, 1, or 2?
>On the implementations I have tried, the dtor for "b" (but not "a")
>gets called, and the exit status is 1. I see nothing in the WP that
>says that the dtor for "a" must not be called (or must be called, for that
>matter).
>Any pointers?
The C++ Working paper only specifies "additional" behaviour for exit() - it
refers to ISO C exit() for basic behaviour, and the ISO C standard
states
"if more than one call to exit() is executed by a program,
the result is undefined".
I'd have to say you're living on the edge.
-simon tooke
===============================================================================
Simon Tooke (not speaking for) SCO Canada, Inc. Voice: (416) 960-4041
....!scocan!simon simon@sco.com Fax: (416) 922-2704
130 Bloor St. West. Suite 1001, Toronto, Ontario, Canada M5S 1N5
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]