This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]