Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!ut-emx!ccwf.cc.utexas.edu!albert From: albert@ccwf.cc.utexas.edu (Albert Wu) Newsgroups: comp.lang.c++ Subject: Exit vs. return in main() using ATT CC Message-ID: <40156@ut-emx.uucp> Date: 26 Nov 90 02:47:08 GMT Sender: news@ut-emx.uucp Reply-To: albert@ccwf.cc.utexas.edu (Albert Wu) Organization: The University of Texas at Austin Lines: 30 Originator: albert@minnie.cc.utexas.edu Dear all: I use ATT CC 2.0. I have a question about using return vs. exit() in the main function. I found that the destructor is not called automatically when I use exit, but it is called if I use return. For example, in the following case: #include class Junk { public: Junk(){ cout << "Constructor called.\n";} ~Junk() { cout << "Destructor called.\n"; } }; main() { Junk idol; exit(1); return 1; } the destructor is not called. However, if I eliminate the exit(1); line, the destructor will be called. Did I do something wrong here ? Is this the way it should be ? Where can I pinpoint documentation about this issue ( difference between exit and return ) ? Pls reply using email also because I don't read the newsgroup regularly. Thanks ahead. -- Albert Wu.