string to char*

Simen kjaeraas simen.kjaras at gmail.com
Sat Sep 11 06:13:59 PDT 2010


shd <alienballance at gmail.com> wrote:

> Hello,
> I'm having a problem in passing a value to char* expecting function
> in D 2.0.

Why does the function expect a char*? If it is an external C function,
and it might change the passed values, you should make a duplicate
mutable string, or use char[] in lieu of string.

If it is an external C function that will *not* change the passed
values, and you have write access to the D headers to interface to C,
use const char* instead. If no write access, I would use
cast(char*)myString.ptr.

If it is a D function, why does it not use const? Or for that matter,
why does it not use char[]?

-- 
Simen


More information about the Digitalmars-d-learn mailing list