string to char* in betterC

rikki cattermole rikki at cattermole.co.nz
Wed Mar 11 16:11:17 UTC 2020


On 12/03/2020 5:07 AM, Abby wrote:
> What is the proper way to get char* from string which is used in c 
> functions? toStringz does returns:
> 
> /usr/include/dmd/phobos/std/array.d(965,49): Error: TypeInfo cannot be 
> used with -betterC
> 
> and I think string.ptr is not safe because it's not zero termined. So 
> what should I do? realloc each string with /0?
> 
> Thank you for your help

String literals are null terminated so you can pass them straight to C.

toStringz will of course not work as that relies on the GC.


More information about the Digitalmars-d-learn mailing list