wstring comparison is failing
Vladimir Panteleev
thecybershadow.lists at gmail.com
Tue Sep 24 21:46:38 UTC 2019
On Tuesday, 24 September 2019 at 21:40:47 UTC, Brett wrote:
> The only issue is that buggy dynamic code can result if someone
> compares the two and it will fail silently.
But, you don't know if the static array actually contains a
null-terminated string (in which case the comparison is a bug) or
an actual meaningful string of that length, such as a string
literal represented as a static array (in which case the
comparison is completely valid).
> It could be quite complex bug that destroys the space station.
The worst kind of bugs are the ones for which the program works
correctly 99.9% of the time (including in all unit tests), but
0.1% of the time things explode. This doesn't seem to me like
that kind of a bug, if only that a NUL character will always be
presented in a zero-terminated string embedded in a static array,
but practically never in a D string.
> If I convert a static array to a string, I want the "string"
> portion of the array.
Zero-terminated strings are kind of a C thing. D isn't C, it has
its own string type. Even though many libraries use a C ABI for
interop, and thus use C strings, this isn't a requirement for a D
program - after all, you can write your own kernel and operating
system in D, all fully without zero-terminated strings.
More information about the Digitalmars-d-learn
mailing list