What exactly are the String literrals in D and how they work?
Tejas
notrealemail at gmail.com
Sun Aug 15 08:53:50 UTC 2021
On Sunday, 15 August 2021 at 08:51:19 UTC, rempas wrote:
> On Sunday, 15 August 2021 at 08:47:39 UTC, jfondren wrote:
>>
>> dup() isn't aware of the NUL since that's outside the slice of
>> the string. It only copies the chars in "John". You can use
>> toStringz to ensure NUL termination:
>> https://dlang.org/phobos/std_string.html#.toStringz
>
> Is there something bad than just casting it to `char*` that I
> should be aware of?
External C libraries expect strings to be null terminated, so if
you do use `.dup`, use `.toStringz` as well.
More information about the Digitalmars-d-learn
mailing list