This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Wanted: if new returns NULL, don't run constructor
- To: egcs at egcs dot cygnus dot com
- Subject: Wanted: if new returns NULL, don't run constructor
- From: Greg McGary <gkm at eng dot ascend dot com>
- Date: Fri, 26 Feb 1999 13:05:43 -0700
- Cc: balsup at eng dot ascend dot com, gkm at eng dot ascend dot com
In a legacy embedded system that's tight on memory, I can't afford
exception handling. Neither is it useful to handle memory allocation
failures with a new_handler. What I'd like to see is `new OBJ' return
NULL on failure, and for OBJ's constructor to detect (this==NULL) and
return immediately. The caller of new can then check for NULL and
decide what to do.
Would it be a reasonable extension to make g++ generate the
(this==NULL) check at the head of constructors? Is there a better way
to implement the desired behavior?