Calling a C Function with C-style Strings

"Nordlöw" per.nordlow at gmail.com
Sat Nov 30 07:48:26 PST 2013


I'm struggling to call mktemp in D:

     import core.sys.posix.stdlib;
     import std.string: toStringz;
     auto name = "alpha";
     auto tmp = mktemp(name.toStringz);

but I can't figure out how to use it so DMD complains:

     /home/per/Work/justd/fs.d(1042): Error: function 
core.sys.posix.stdlib.mktemp (char*) is not callable using 
argument types (immutable(char)*)

How do I create a mutable zero-terminated C-style string?

I think I've read somewhere that string literals (`const` or 
`immutable`) are implicitly convertible to zero (null)-terminated 
strings.


More information about the Digitalmars-d-learn mailing list