Transferring global variables from D to C
Jimmy Cao
jcao219 at gmail.com
Sat Oct 1 18:37:39 PDT 2011
I'm not sure.
Try __gshared string str = "a";
2011/10/1 Dainius (GreatEmerald) <pastas4 at gmail.com>
> > 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20111001/7daadb7b/attachment.html>
More information about the Digitalmars-d-learn
mailing list