home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13337 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  1.9 KB

  1. Path: sparky!uunet!igor!thor!rmartin
  2. From: rmartin@thor.Rational.COM (Bob Martin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Destructors and exit()
  5. Message-ID: <rmartin.715714712@thor>
  6. Date: 5 Sep 92 17:38:32 GMT
  7. References: <1992Sep3.220301.16983@murdoch.acc.Virginia.EDU> <rmartin.715615353@thor> <2384@devnull.mpd.tandem.com> <rmartin.715701864@thor>
  8. Sender: news@Rational.COM
  9. Lines: 41
  10.  
  11. rmartin@thor.Rational.COM (Bob Martin) writes:
  12.  
  13. |rgp@mpd.tandem.com (Ramon Pantin) writes:
  14.  
  15. ||IMHO, it would be incorrect for a compiler to "know" anything about
  16. ||exit (exit is part of the C library, not part of the language, "exit"
  17. ||is not a keyword).  A call to the exit function has never triggered
  18. ||destructions of automatic objects and should never do.  The block where
  19. ||the object was constructed is not being exited when the exit function
  20. ||is called so it is incorrect to destroy the object. 
  21.  
  22. |In general I agree with this. But I have seen compilers which have
  23. |taken such liberties.  
  24.  
  25. I was running around the track at the health club today.  About two
  26. miles into my run, the following thought occured to me: 
  27.  
  28. A reasonable implementation of exit would be:
  29.  
  30. void exit(int status)
  31. {
  32.   throw(exitException(status));
  33. }
  34.  
  35. Presumably this exception would be caught by the preamble code which
  36. calls 'main'.  Such an implementation of 'exit' *would* cause the
  37. destructors of all currently existing auto variables to be called.
  38.  
  39. Now, 'exit' is not currently defined this way, and I don't know if any
  40. of the compiler manufacturers are even considering it.  But the above
  41. implementation is defensible, and perhaps even superior to the current
  42. implementation.
  43.  
  44. Just a thought.
  45.  
  46.  
  47. --
  48. Robert Martin                        Training courses offered in:
  49. R. C. M. Consulting                       Object Oriented Analysis
  50. 2080 Cranbrook Rd.                        Object Oriented Design
  51. Green Oaks, Il 60048 (708) 918-1004       C++
  52.