本文介绍了使用“-fno-exceptions”,“new T”会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道,如果我使用<$ c $编译我的程序,将会 new T
仍然引用 bad_alloc
c> -fno-exceptions 选项禁用异常处理?
I was wondering, will new T
still throw bad_alloc
if I compile my program using the -fno-exceptions
option to disable exception handling?
或者编译器(GCC和clang支持该选项) 新T
到新(nothrow)T
?
Or will the compiler (GCC and clang support that option) implicitly transform the use of new T
to new (nothrow) T
?
推荐答案
我不能给一个明确的答案围绕-fno异常所有的优点,只是在32位linux机器上的观察,gcc 4.5.1 - bad_alloc抛出和没有 -fno-exceptions
I can't give a definitive answer to all the perks around -fno-exceptions, just the observations on a 32 bit linux machine, gcc 4.5.1 - bad_alloc is thrown with and without -fno-exceptions
[21:38:35 1 ~/tmp] $ cat bad_alloc.cpp
int main()
{
char* c = new char[4000000000U];
}
[21:38:58 1 ~/tmp] $ g++ bad_alloc.cpp
[21:39:06 1 ~/tmp] $ ./a.out
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted
[21:39:07 1 ~/tmp] $ g++ -fno-exceptions bad_alloc.cpp
[21:39:16 1 ~/tmp] $ ./a.out
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted
这篇关于使用“-fno-exceptions”,“new T”会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!