🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Calling exit() from the dtor of a static object

#2302
From: Simon Tooke
Date: Wed, 25 Oct 1995 17:33
51 lines
1919 bytes

In <951024.195404z.11077.das@lanai.cs.ucla.edu> David A Smallberg <das@CS.UCLA.EDU> writes:

>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?

The C++ Working paper only specifies "additional" behaviour for exit() - it
refers to ISO C exit() for basic behaviour, and the ISO C standard
states

	"if more than one call to exit() is executed by a program, 
	 the result is undefined".

I'd have to say you're living on the edge.

-simon tooke

===============================================================================
Simon Tooke  (not speaking for) SCO Canada, Inc.         Voice:  (416) 960-4041
....!scocan!simon             simon@sco.com                Fax:  (416) 922-2704
130 Bloor St. West. Suite 1001, Toronto, Ontario, Canada  M5S 1N5




---
[ 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: <DH0CBG.GJD@sco.COM>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
References: <951024.195404z.11077.das@lanai.cs.ucla.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: simon@sco.COM (Simon Tooke)
Newsgroups: comp.std.c++
Subject: Re: Calling exit() from the dtor of a static object
Date: 25 Oct 1995 17:33:50 GMT
Organization: SCO Canada, Inc.
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <DH0CBG.GJD@sco.COM>
References: <951024.195404z.11077.das@lanai.cs.ucla.edu>
NNTP-Posting-Host: physics2.berkeley.edu