reading a global external (C) char* in D2
Graham Fawcett
fawcett at uwindsor.ca
Sun Apr 18 10:17:00 PDT 2010
On Sun, 18 Apr 2010 19:14:33 +0200, Lars T. Kyllingstad wrote:
> Graham Fawcett wrote:
>> Hi folks,
>>
>> I'm having trouble reading an external(C) global value in D2. I think
>> I'm using __gshared properly to sidestep the TLS issues, but I'm still
>> getting an incorrect result.
>>
>> Consider the two following programs, one in C, the other D2:
>>
>> // testc.c
>> #include <stdio.h>
>> extern char *gdbm_version; // or #include <gdbm.h>
>>
>> int main() {
>> printf("VERSION (C): %s.\n", gdbm_version);
>> }
>>
>> $ gcc -o testc testc.c -lgdbm && ./testc VERSION (C): GDBM version
>> 1.8.3. 10/15/2002 (built Nov 5 2008 02:36:47).
>>
>> // testd.d
>> import std.stdio;
>> import std.conv;
>>
>> __gshared extern (C) char *gdbm_version;
>>
>> void main() {
>> string v = to!string(gdbm_version);
>> writef("VERSION (D): %s.\n", v);
>> }
>>
>> $ dmd testd.d -L-lgdbm && ./testd
>> VERSION (D): .
>>
>> Am I doing something wrong?
>>
>> Thanks,
>> Graham
>
>
> Try adding a second 'extern':
>
> extern(C) extern __gshared char* gdbm_version;
That did it! Thank you. I have much to learn.
Cheers,
Graham
>
> -Lars
More information about the Digitalmars-d-learn
mailing list