🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Global Init/Shutdown: A solution (hopefully)

#2521
From: JdeBP
Date: Sat, 11 Nov 1995 06:06
48 lines
1902 bytes
Further to the global initialisation/cleanup discussion, can anyone tell me
when `woggle::~woggle' is called in the following program ?  Is undefined
behaviour invoked ?

If you think that the program is non-conforming (aside from any
typographical mistakes that I make, which I'm sure that you'll overlook in
view of the latesness of the hour, and the fact that I'm typing this in by
hand) please explain where and why it is non-conforming.

//
//  **************************************************************
//	WOGGLE     -- Jonathan de Boyne Pollard  19951111
//  **************************************************************
//

#include <stdlib.h>

class woggle {
public:
	char * p ;
	woggle() p(new(nothrow()) char) {}
	~woggle() { char * q = p ; p = 0 ; delete q ; }
} ;

void * 
std::operator new ( size_t s, const std::nothrow & ) throw()
{ 
	return malloc(s) ; 
}

void 
std::operator delete ( void * p ) throw()
{
	static woggle w ;
	*w.p = ' ' ;
	free(p) ;
}

int
main ( int, char ** )
{
	delete new(nothrow()) char ;
	return EXIT_SUCCESS ;
}
---
[ 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: <199511110341.UAA26529@ncar.ucar.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: 11 Nov 95 06:06:21 GMT
Approved: fjh@cs.mu.oz.au
From: JdeBP@jba.co.uk
Message-ID: <199511110341.UAA26529@ncar.ucar.EDU>
X-Original-Date: Sat, 11 Nov 1995 02:41:02 GMT
Subject: Re: Global Init/Shutdown: A solution (hopefully)
Newsgroups: comp.std.c++
Organization: JBA Software Products, Studley, England.
Reply-To: JdeBP%utopium@jba.co.uk
X-Newsreader: TIN [version 1.2 PL2]
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMKQ9Z+EDnX0m9pzZAQFw4gF+MbRfEmElgv6OIuAl3cBGr2KEmGRZ4fGJ
 aG3Sv6Qny7bCRM9NVbYB6pkuO+nXEvHu
 =Qln7