schmidt@glacier.ics.uci.edu (01/06/89)
Hi, I came across an interesting C++ fact the other day. While I can see why this behavior make sense, it seems like it should at least be mentioned in any C++ language reference manual. Here's an example: ---------------------------------------- class foo { public: foo ( ) { printf ( "start\n" ); } ~foo ( void ) { printf ( "finish\n" ); } }; main ( ) { foo bar; // prints "start" exit ( 0 ); // doesn't print "finish", since exit() doesn't return! // replacing exit(0) with return 0 works. } ---------------------------------------- Most C programmers are probably conditioned to use exit(), rather than return, in the main() function. While this doesn't make much difference in C, it obviously make a *big* difference in C++, if objects with destructors are defined in the main() function. I don't recall this being mentioned explicitly in the C++ reference manual. Page 159 alludes to the differences with exit(), abort(), and destructors for static objects. Mention of this behavior probably belongs go in the ``Differences with C'' section. I hope this information saves people problems in the future. Doug -- schmidt@ics.uci.edu (ARPA) | Per me si va nella citta' dolente. office: (714) 856-4043 | Per me si va nell'eterno dolore. | Per me si va tra la perduta gente. | Lasciate ogni speranza o voi ch'entrate.