New and exception
Joe Buck
Joe.Buck@synopsys.com
Thu Jul 25 03:06:00 GMT 2002
Jamie Lokier writes:
> In certain high-performance programs, I use -fno-exceptions (for better
> optimisation; I know there are no exceptions), and I do _not_ use the
> nothrow version of new() precisely because I know that new() will never
> return NULL, and I don't want the constructors to check for this.
> (If the program really does run out of memory, it is terminated the hard
> way as with xmalloc()).
>
> For this reason, I don't declare new() as throw() -- because GCC will
> then check for NULL, which I'd rather it did not.
>
> So, please don't make it so I cannot disable NULL checks and disable
> exceptions at the same time.
This argument makes a lot of sense to me. The alternative smacks of
trying to make C++ work the way it did 10 years ago, which is hopeless
because there are too many other differences.
It's not asking too much to ask people who want the behavior of
new-nothrow to write it explicitly as the standard calls for, even when
using -fno-exceptions. The interpretation of using -fno-exceptions in a
context where new can fail to allocate memory is that we expect the
program to die if this occurs.
More information about the Gcc
mailing list