Thread View: comp.std.c++
2 messages
2 total messages
Started by David A Smallberg
Wed, 25 Oct 1995 02:36
Calling exit() from the dtor of a static object
Author: David A Smallberg
Date: Wed, 25 Oct 1995 02:36
Date: Wed, 25 Oct 1995 02:36
27 lines
1290 bytes
1290 bytes
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?
---
[ 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. ]
Re: Calling exit() from the dtor of a static object
Author: Simon Tooke
Date: Wed, 25 Oct 1995 17:33
Date: Wed, 25 Oct 1995 17:33
51 lines
1919 bytes
1919 bytes
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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads