c++ - operator new() still returns NULL?!
Is this correct? I've just been surprised to see that the following
code produces "NULL returned", and not "bad_alloc"
{
try
{
char *pch = new char[2000000000];
if(NULL == pch)
{
fprintf(stderr, "NULL returned\n");
}
}
catch(std::bad_alloc &)
{
fprintf(stderr, "bad_alloc\n");
}
catch(std::exception &x)
{
fprintf(stderr, "exception: %s\n", x.what());
}
catch(...)
{
fprintf(stderr, "exception of unknown type\n");
}
}
What gives?!
Matthew
Jul 03 2005
"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:daad5l$2t23$1 digitaldaemon.com...Is this correct? I've just been surprised to see that the following code produces "NULL returned", and not "bad_alloc"It still returns NULL, that's correct. It's that way to support older code, such as MFC. I know it'll eventually have to be fixed.
Jul 04 2005
I've found a workaround, in that I've emulated the somewhat scary tactic of DMC++'s STLport that throws bad_alloc from std::allocator even though operator new() does not. Still, it will have to be fixed. ;) "Walter" <newshound digitalmars.com> wrote in message news:daaqqi$dpa$2 digitaldaemon.com..."Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:daad5l$2t23$1 digitaldaemon.com...Is this correct? I've just been surprised to see that the following code produces "NULL returned", and not "bad_alloc"It still returns NULL, that's correct. It's that way to support older code, such as MFC. I know it'll eventually have to be fixed.
Jul 04 2005








"Matthew" <admin stlsoft.dot.dot.dot.dot.org>