Transferring global variables from D to C
Dainius (GreatEmerald)
pastas4 at gmail.com
Sat Oct 1 11:20:50 PDT 2011
> However, this gets quite inefficient with a lot of different strings,
I just had an idea, perhaps it's possible to work around this
particular point by creating a wrapper function that converts the
passed variable into the C string type? The problem with this idea is
that I can't find a way to pass the variable to begin with. Whenever I
try to do that, D receives an empty string. My C code is this:
extern char* str;
printf("string is %s\n", getString(str));
While the D code is this:
shared string str="a";
extern(C) immutable(char)* getString(string MyString)
{
writeln("Attempting to convert ", MyString);
return toStringz(MyString);
}
This results in "Attempting to convert ", and not "Attempting to
convert a", so obviously D is not getting the right data. But it
doesn't segfault, either.
More information about the Digitalmars-d-learn
mailing list