Re: Core dump constructing a C++ string with NULL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 14 January 2011 17:05, Jonathan Wakely wrote:
> 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.

... std::string("\0") is also empty.

But passing '\0' to the string constructor creates a string containing a '\0'



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux