Alex Vinokur wrote:
What is difference between
delete p;
and
delete(nothrow) p;
?
Well, let's run an experiment and see:
int main()
{
int* p = new int;
delete p;
}
Compiling with Comeau Test Drive ...
Thank you for testing your code with Comeau C/C++!
Tell others about
http://www.comeaucomputing.com/tryitout !
Your Comeau C/C++ test results are as follows:
Comeau C/C++ 4.3.8 (Aug 19 2006 13:36:48) for
ONLINE_EVALUATI ON_Alpha1
Copyright 1988-2006 Comeau Computing. All rights reserved.
MODE:strict errors C++
In strict mode, with -tused, Compile succeeded (but remember,
the Comeau online
compiler does not link)."
OK, so that seemed to work fine.
Now let's try this:
int main()
{
int* p = new int;
delete (nothrow) p;
}
Compiling again with Comeau Test Drive...
Thank you for testing your code with Comeau C/C++!
Tell others about
http://www.comeaucomputing.com/tryitout !
Your Comeau C/C++ test results are as follows:
Comeau C/C++ 4.3.8 (Aug 19 2006 13:36:48) for
ONLINE_EVALUATI ON_Alpha1
Copyright 1988-2006 Comeau Computing. All rights reserved.
MODE:strict errors C++
"ComeauTest .c", line 4: error: identifier "nothrow" is undefined
delete (nothrow) p;
^
"ComeauTest .c", line 4: error: expected a ";"
(perhaps on the previous statement)
delete (nothrow) p;
^
2 errors detected in the compilation of "ComeauTest .c".
In strict mode, with -tused, Compile failed
Hit the Back Button to review your code and compile options.
So it appears that the first is legal C++ and the second is a syntax
error.
Best regards,
Tom