Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I convince my (older) compiler to automatically check new to see if it returns NULL?

0
Posted

How can I convince my (older) compiler to automatically check new to see if it returns NULL?

0

[Recently fixed bugs: new handlers don’t take arguments, thanks to Scott Aaron; changed set_new_hanlder to set_new_handler, thanks to Peter Andersson (on 1/97). Click here to go to the next FAQ in the “chain” of recent changes.] Eventually your compiler will. If you have an old compiler that doesn’t automagically perform the NULL test, you can force the runtime system to do the test by installing a “new handler” function. Your “new handler” function can do anything you want, such as print a message and abort() the program, delete some objects and return (in which case operator new will retry the allocation), throw an exception, etc. Here’s a sample “new handler” that prints a message and calls abort().

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123