extern __gshared const(char)* symbol fails

James Blachly james.blachly at gmail.com
Fri Aug 31 06:20:09 UTC 2018


Hi all,

I am linking to a C library which defines a symbol,

const char seq_nt16_str[] = "=ACMGRSVTWYHKDBN";

In the C sources, this is an array of 16 bytes (17 I guess, 
because it is written as a string).

In the C headers, it is listed as extern const char 
seq_nt16_str[];

When linking to this library from another C program, I am able to 
treat seq_nt16_str as any other array, and being defined as [] 
fundamentally it is a pointer.

When linking to this library from D, I have declared it as:

extern __gshared const(char)* seq_nt16_str;

***But this segfaults when I treat it like an array (e.g. by 
accessing members by index).***

Because I know the length, I can instead declare:

extern __gshared const(char)[16] seq_nt16_str;

My question is: Why can I not treat it opaquely and use it 
declared as char* ? Does this have anything to do with it being a 
global stored in the static data segment?



More information about the Digitalmars-d-learn mailing list