C++: operator new and disabled exceptions

Christophe LYON christophe.lyon@st.com
Thu Sep 27 19:01:00 GMT 2007


Hi,

Thanks for this simple solution.

Yet, why isn't this the default when using -fno-exceptions ?

Christophe.


On 27.09.2007 15:31, Richard Li wrote:
> Hi,
> 
> I tried to redefine the global "new" operator like the following code,
> and it seems to work.
> 
> #include <new>
> void * operator new (size_t n)
> {
>  return operator new (n, std::nothrow);
> }
> 
> void * operator new [] (size_t n)
> {
>  return operator new [] (n, std::nothrow);
> }
> 
> 
> On 9/27/07, Christophe LYON <christophe.lyon@st.com> wrote:
>> Hello,
>>
>> I am compiling a C++ application, which uses the 'new' operator, with
>> exceptions disabled (-fno-exceptions).
>>
>> Yet, the new operator called is the one that throws an exception in case
>> of failure. Why is it so ? Isn't it inconsistent with the
>> -fno-exceptions flag?
>>
>> I imagined that compiling with -fno-exceptions would make the compiler
>> generate calls to new(nothrow) instead.
>>
>> In my case, replacing all calls to new to new(nothrow) in the
>> application is not an option.
>>
>> Thanks,
>>
>> Christophe.
>>
>>
> 



More information about the Gcc-help mailing list