home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!igor!thor!rmartin
- From: rmartin@thor.Rational.COM (Bob Martin)
- Newsgroups: comp.lang.c++
- Subject: Re: Destructors and exit()
- Message-ID: <rmartin.715714712@thor>
- Date: 5 Sep 92 17:38:32 GMT
- References: <1992Sep3.220301.16983@murdoch.acc.Virginia.EDU> <rmartin.715615353@thor> <2384@devnull.mpd.tandem.com> <rmartin.715701864@thor>
- Sender: news@Rational.COM
- Lines: 41
-
- rmartin@thor.Rational.COM (Bob Martin) writes:
-
- |rgp@mpd.tandem.com (Ramon Pantin) writes:
-
- ||IMHO, it would be incorrect for a compiler to "know" anything about
- ||exit (exit is part of the C library, not part of the language, "exit"
- ||is not a keyword). A call to the exit function has never triggered
- ||destructions of automatic objects and should never do. The block where
- ||the object was constructed is not being exited when the exit function
- ||is called so it is incorrect to destroy the object.
-
- |In general I agree with this. But I have seen compilers which have
- |taken such liberties.
-
- I was running around the track at the health club today. About two
- miles into my run, the following thought occured to me:
-
- A reasonable implementation of exit would be:
-
- void exit(int status)
- {
- throw(exitException(status));
- }
-
- Presumably this exception would be caught by the preamble code which
- calls 'main'. Such an implementation of 'exit' *would* cause the
- destructors of all currently existing auto variables to be called.
-
- Now, 'exit' is not currently defined this way, and I don't know if any
- of the compiler manufacturers are even considering it. But the above
- implementation is defensible, and perhaps even superior to the current
- implementation.
-
- Just a thought.
-
-
- --
- Robert Martin Training courses offered in:
- R. C. M. Consulting Object Oriented Analysis
- 2080 Cranbrook Rd. Object Oriented Design
- Green Oaks, Il 60048 (708) 918-1004 C++
-