Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 1 Jun 1997 02:40:43 +0200
From:      j@uriah.heep.sax.de (J Wunsch)
To:        freebsd-hackers@freebsd.org (FreeBSD hackers)
Cc:        un_x@anchorage.net (Steve Howe)
Subject:   Re: Borland 16bit bcc vs cc/gcc (float)
Message-ID:  <19970601024043.PG35696@uriah.heep.sax.de>
In-Reply-To: <1.5.4.32.19970531220152.008b46f0@mindspring.com>; from Kevin P. Neal on May 31, 1997 18:01:52 -0400
References:  <1.5.4.32.19970531220152.008b46f0@mindspring.com>

next in thread | previous in thread | raw e-mail | index | archive | help
As Kevin P. Neal wrote:

> Who says you always have to use exit()?
> 
> In fact, I've observed C++ code that never calls the destructors if you
> exit() of out a program.

Global destructors should be called.  Destructors for objects local to
main(), of course, not.

j@uriah 119% cat foo.cc
#include <ostream.h>
#include <stdlib.h>

class myobj {
	static int count;
  public:
	myobj() { cout << "Created my object # " << ++count << "\n"; }
	~myobj() { cout << "Destroyed my object, " << --count <<
		" remaining.\n"; }
};

int myobj::count = 0;

myobj y;

int
main(int argc, char **argv)
{
	myobj x;

	if (argc > 1)
		exit(0);
}
j@uriah 120% c++ foo.cc
j@uriah 121% ./a.out
Created my object # 1
Created my object # 2
Destroyed my object, 1 remaining.
Destroyed my object, 0 remaining.
j@uriah 122% ./a.out "call exit() now"
Created my object # 1
Created my object # 2
Destroyed my object, 1 remaining.

-- 
cheers, J"org

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19970601024043.PG35696>