Passing string literals to C
Laeeth Isharc via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Dec 31 03:19:35 PST 2014
Argh - no way to edit.
What's best practice here?
D strings are not null-terminated.
===
cpling.c
char* cpling(char *s)
{
s[0]='!';
return s;
}
===
dcaller.d
extern(C) char* cpling(char* s);
void callC()
{
writefln("%s",fromStringz(cpling("hello\0")));
}
or
void callC()
{
writefln("%s",fromStringz(cpling(toStringz("hello"))));
}
===
am I missing a better way to do this?
More information about the Digitalmars-d-learn
mailing list