This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Core dump constructing a C++ string with NULL
On 14 January 2011 16:59, Tom Browder wrote:
>
> Two questions:
>
> 1. ?does it take any significant time difference to check for a 0
> versus throw an exception (one argument against)?
You have to check for 0 to decide whether to throw an exception or not.
(The alternative is to not check, and segfault, which was the old
behaviour in libstdc++)
I couldn't care less about how slow the function is in the case of a
precondition violation (null string, the exceptional path). We do care
about the performance of the correct case (non-null string.)
> 2. ?Isn't a '\0' an empty string in the string context?
std::string("") is an empty string. std::string('\0') is not.