The more interesting question

Christophe Travert travert at phare.normalesup.org
Tue May 22 00:17:56 PDT 2012


"Jonathan M Davis" , dans le message (digitalmars.D:167901), a écrit :
> On Friday, May 18, 2012 11:18:46 Steven Schveighoffer wrote:
>> On Fri, 18 May 2012 11:05:21 -0400, Christophe Travert
>> 
>> <travert at phare.normalesup.org> wrote:
>> > "Steven Schveighoffer" , dans le message (digitalmars.D:167556), a
>> > 
>> >> toStringz can allocate a new block in order to ensure 0 gets added.
>> >> This
>> >> is ludicrous!
>> >> 
>> >> 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*
>> >> it's safe.
>> > 
>> > How about "mystring\0".ptr ?
>> 
>> AKA "mystring" :)
>> 
>> I'm sorry, I don't see the reason to require this. All for the sake of
>> making "" a null slice. I find the net gain quite trivial.
> 
> And I find the net gain to be negative, since the fact that "" is non-null is 
> _useful_.
> 
> - Jonathan M Davis

I'm not saying "" should point to null. I'm saying people claiming that 
they have to heap-allocate (via toStringz) each time they call a 
c-function are just wrong. I tend to accept the point that making 
strings automatically zero terminated for making calls to c-function 
easier is not such a good idea, but I have no problem with [] !is "". 
Empty strings should be tested with empty.

-- 
Christophe


More information about the Digitalmars-d mailing list