Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!wuarchive!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: How do I call destructors on ^C in TC++? Message-ID: <747@taumet.com> Date: 24 May 91 17:20:21 GMT References: <1991May24.045847.24401@colorado.edu> Organization: Taumetric Corporation, San Diego Lines: 32 scholes@spot.Colorado.EDU (Genuine Bud Man) writes: > Please excuse me if this is a FAQ, or if I am missing something >painfully obvious, but destructors don't seem to be called when >the user hits ^C in Turbo C++. Until exceptions are part of the language, this is the problem of interrupted control flow. If you have a local object and suddenly jump out of the function where it was constructed (as from an interrupt or longjmp) the destructor will not be called, and there is no way to ensure that it will be called. Destructors for static objects will be called if you exit the program normally, by returning from main() or by calling exit(). If you call abort(), these destructors will not be called. If you want a graceful exit from a program which may be interrupted: 1. Avoid local objects which have destructors with important side effects. You have to assume that the destructors might not be called unless you disable interrupts during the lifetime of those objects. 2. Catch the keyboard interrupt and do whatever cleanup is needed; then call exit(). An unimportant side effect is freeing storage. An important side effect might be flushing an output buffer or restoring terminal attributes. -- Steve Clamage, TauMetric Corp, steve@taumet.com