C is Brittle D is Plastic
Quirin Schroll
qs.il.paperinik at gmail.com
Mon Apr 27 12:24:59 UTC 2026
On Monday, 13 April 2026 at 10:20:33 UTC, Dejan Lekic wrote:
> On Monday, 13 April 2026 at 09:56:19 UTC, Quirin Schroll wrote:
>> If you don’t do C interop yourself, it won’t affect you.
>>
>> If you do C interop, replacing all your `""` literals by `""z`
>> literals is a simple regex replace away plus a linter
>> configuration that keeps you from accidentally using `""`.
>> However, I don’t think you pass many slice typed things to C
>> functions. If you don’t use a linter on a big project, I’d say
>> that’s on you as well.
>>
>> I expected this to be controversial, but not to that degree.
>
> Luckily this is just an edition so I do not need to use it. - I
> wonder who will?
>
> Is there a comprehensive document describing this decision (DIP
> perhaps)?
No, this was just a thought (maybe a DIP idea) that I had reading
the posts.
> I am curious to know what do you do when you use packageX that
> contains a function that takes a string - how do you know
> whether you pass it a new "" string or ""z string?
If you use a package, you should generally know how to use it. If
a function is halfway decently written, it’ll take strings as
`const(char)[]` if it doesn’t expect zero termination. If a
function takes a `const(char)*`, you already have to read the
docs for details, though generally speaking, most of those expect
a NUL-terminated string. If you call such a function with a `""`
literal, it would become NUL-terminated because of that reason. I
definitely mentioned this exception. Essentially, a `""` string
passed to a `const(char)*` directly would be as if you wrote a
`""z` string.
> You need to go and read the code to understand what that
> function does, right? Or ""z is not a "string" but some other
> type (zstring)?
The type of `""z` would be `string`. Essentially, `"abc"z` is
just `"abc\0"[0..$-1]`.
More information about the Digitalmars-d
mailing list