From: Olly B. <ol...@su...> - 2003-04-02 17:56:31
|
On Wed, Apr 02, 2003 at 09:49:46AM -0800, Jeremy Fitzhardinge wrote: > On Wed, 2003-04-02 at 08:34, Olly Betts wrote: > > > On Wed, Apr 02, 2003 at 11:23:34AM -0500, Maarten Ballintijn wrote: > > > > > { > > > > > std::string s; > > > > > s += '0'; > > > > > } > > > > > exit(0); > > > > > Just out of curiosity, why would s be destructed if you call exit()? > > > > s is destructed at the end of the block where it's defined - i.e. the > > line before exit is called. > > Do you mean the compiler is treating exit specially? No. Look at the code. s is destructed at the end of the block it is defined in. That's how C++ works. What happens after the block is irrelevant to that destruction. > Is that because > its a noreturn function? That still can't be right: if it were a > noreturn function which takes a std::string argument, then it would be > wrong to destruct the string before passing it. But it couldn't take s as an argument, as s isn't in scope at that point! Cheers, Olly |