🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2296

Calling exit() from the dtor of a static object

#2296
From: David A Smallberg
Date: Wed, 25 Oct 1995 02:36
27 lines
1290 bytes
Although I know what some implementations do, I can't determine from
the Working Paper what should happen in this case:

	int n = 0;

	struct X {
		~X() { exit(++n); }
	};

	X a;
	X b;
	int main()
	{
		exit(n);
	}

Does the destructor for "a" get called?  Is the exit status 0, 1, or 2?
On the implementations I have tried, the dtor for "b" (but not "a")
gets called, and the exit status is 1.  I see nothing in the WP that
says that the dtor for "a" must not be called (or must be called, for that
matter).

Any pointers?
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <951024.195404z.11077.das@lanai.cs.ucla.edu>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 25 Oct 95 02:36:16 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
X-Original-Date: Tue, 24 Oct 95 12:54:04 PDT
From: David A Smallberg <das@CS.UCLA.EDU>
Message-ID: <951024.195404z.11077.das@lanai.cs.ucla.edu>
Subject: Calling exit() from the dtor of a static object
Organization: UCLA, Computer Science Department
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMI2iseEDnX0m9pzZAQEi0AF+NieU6uw1AuUUPMgHGxQDN8JufY/kMs0M
 9DniEUg7GLqvnBD0MwPfH4VfsVbH4orK
 =cXxI