On 10/22/2017 06:41 PM, Shriramana Sharma wrote:
> On Sunday, 22 October 2017 at 15:21:37 UTC, Shriramana Sharma wrote:
>> For my program right now I'm using a souped-up version using a static
>> array:
>>
>>     char[20] name = "/tmp/XXXXXX";

Literal strings have a '\0' attached, which does not become a part of the slice.

> Hmm I was wondering if I needed it to be static, and verily, substituting:
>
> char[] name = "/tmp/XXXXXX".dup;

However, .dup is not be aware of the special literal treatment so it does not copy the '\0' character.

> Is it because the D slice is subject to relocation and C is occasionally
> not able to access the proper pointer?

As long as you have a reference on the D side, the slice will remain valid. The actual issue is the missing '\0'. So, consider toStringz in this case:

  https://dlang.org/library/std/string/to_stringz.html

Ali

Reply via email to