reading a global external (C) char* in D2

Graham Fawcett fawcett at
Sun Apr 18 10:10:55 PDT 2010

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

Am I doing something wrong? 


More information about the Digitalmars-d-learn mailing list