Idea: Introduce zero-terminated string specifier

deadalnix deadalnix at gmail.com
Tue Oct 2 06:08:48 PDT 2012


Le 02/10/2012 03:13, Walter Bright a écrit :
> 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.

Exactly my point.


More information about the Digitalmars-d mailing list