Idea: Introduce zero-terminated string specifier

Walter Bright newshound1 at digitalmars.com
Mon Oct 1 18:13:47 PDT 2012


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)];
>
> It is clean and avoid to modify the stdlib in an unsafe way.


Of course, using strlen() is always going to be unsafe. But having %zs 
is equally unsafe for the same reason.

deadalnix's example shows that adding a new format specifier %zs adds 
little value, but it gets much worse. 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.


More information about the Digitalmars-d mailing list