exern (C) linkage problem
bearophile
bearophileHUGS at lycos.com
Mon Jul 19 15:01:25 PDT 2010
> typedef char* Cstring;
> extern(C) Cstring strcmp(Cstring s1, Cstring s2);
> ...
You can use just a struct too:
import std.string: toStringz;
struct Cstring {
const(char)* ptr;
}
extern(C) Cstring strcmp(Cstring s1, Cstring s2);
Cstring toCString(T)(T[] s) {
return Cstring(toStringz(s));
}
void main() {
auto s1 = "abba";
auto s2 = "red";
// auto r = strcmp(toCString(s1), s2); // compile error
auto r = strcmp(toCString(s1), toCString(s2)); // OK
}
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list