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.715701864@thor>
- Date: 5 Sep 92 14:04:24 GMT
- References: <1992Sep3.220301.16983@murdoch.acc.Virginia.EDU> <rmartin.715615353@thor> <2384@devnull.mpd.tandem.com>
- Sender: news@Rational.COM
- Lines: 32
-
- rgp@mpd.tandem.com (Ramon Pantin) writes:
-
- |In article <rmartin.715615353@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
- |>main()
- |>{
- |> MyClass A;
- |> static MyClass B;
- |>
- |> exit();
- |>}
- |>
- |>
- |>The destructor for B should be invoked. But the destructor for A
- |>probably will not. I say probably, because a clever compiler might be
- |>able to figure out that, upon exit, the enclosing stack frames should
- |>be destroyed.
-
- |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.
-
- --
- 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++
-