The more interesting question
schveiguy at yahoo.com
Wed May 16 06:25:40 PDT 2012
On Tue, 15 May 2012 18:31:26 -0400, deadalnix <deadalnix at gmail.com> wrote:
> Le 15/05/2012 17:51, Christophe a écrit :
>> deadalnix , dans le message (digitalmars.D:167404), a écrit :
>>> This looks to me like a bad practice. C string and D string are
>>> different beasts, and we have toStringz .
>> C string and D string are different, but it's not a bad idea to have
>> string *literals* that works for both C and D strings, otherwise using
>> printf will lead to a bug each time the programmer forget the trailing
> Due to slicing, it is already unsafe to pass a D string to C code. The
> main problem is array casting silently to pointers, making the error
> easy to do.
How so? strings are immutable, and literals are *truly* immutable.
> Fixing the problem for literal isn't going to solve it at all.
> The real solution is toStringz
toStringz can allocate a new block in order to ensure 0 gets added. This
You are trying to tell me that any time I want to call a C function with a
string literal, I have to first heap-allocate it, even though I *know*
I don't see a "problem" anywhere. The current system is perfect for what
it needs to do.
More information about the Digitalmars-d