This is the mail archive of the egcs@egcs.cygnus.com mailing list for the EGCS project. See the EGCS home page for more information.


[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index] [Subject Index] [Author Index] [Thread Index]

Wanted: if new returns NULL, don't run constructor



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?