Idea: Introduce zero-terminated string specifier

Jakob Ovrum jakobovrum at gmail.com
Tue Oct 2 16:56:43 PDT 2012


On Tuesday, 2 October 2012 at 21:30:35 UTC, Andrej Mitrovic wrote:
> On 10/2/12, Walter Bright <newshound1 at digitalmars.com> wrote:
>> On 9/30/2012 11:31 AM, deadalnix wrote:
>>> If you know that a string is 0 terminated, you can easily 
>>> create a slice
>>> from it as follow :
>>>
>>> char* myZeroTerminatedString;
>>> char[] myZeroTerminatedString[0 .. 
>>> strlen(myZeroTerminatedString)];
>> Since %zs is inherently unsafe, it
>> hides such unsafety in a commonly used library function, which 
>> will
>> infect everything else that transitively calls writefln with 
>> unsafety.
>>
>> This makes %zs an unacceptable feature.
>
> How does it hide anything if you have to explicitly mark the 
> format
> specifier as %zs? It would be documented, just like it's 
> documented
> that passing pointers to garbage-collected memory to the C side 
> is
> inherently unsafe.

writefln cannot be @safe if it has to support an unsafe format 
specifier. It's "hidden" because it affects every call to 
writefln, even if it doesn't use the unsafe format specifier.



More information about the Digitalmars-d mailing list