Topic: set_new_handler and malloc
Author: Duncan@rcp.co.uk (Duncan Booth)
Date: Fri, 04 Nov 1994 17:14:20 +0000 Raw View
While browsing through the source of the Microsoft Visual C/C++
libraries I noticed something that seemed a trifle peculiar. Do the
recent drafts of the C++ standard say anything about the legality or
otherwise of this:
In Microsoft C++ the operator new is defined as a simple call to
malloc. It does not check the result of the malloc call and instead
relies on malloc itself to call the new handler if it fails. In other
words any call to malloc that fails will call the new handler whether
or not it was a also call to new.
As far as I can tell the behaviour is undocumented, the manuals
simply talk of set_new_handler in the context of calls to new. All
very well if you don't mix the two, but what if you use an existing C
library in your C++ program? Suddenly your existing library (which
may well check for malloc returning NULL and do something useful like
releasing some memory) fails to run in the expected way.
Is there anything in the standard that permits or denies this
behaviour?
--
Duncan Booth duncan@rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?