extern __gshared const(char)* symbol fails

Steven Schveighoffer schveiguy at gmail.com
Fri Aug 31 17:51:07 UTC 2018


On 8/31/18 1:18 PM, Neia Neutuladh wrote:
> On Friday, 31 August 2018 at 06:20:09 UTC, James Blachly wrote:
>> 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).***
> 
> I believe this should be extern extern(C)? I'm surprised that this 
> segfaults rather than having a link error.

Yeah, I had to add extern(C) in my tests to get it to link. I think he 
must have extern(C): somewhere above.

-Steve


More information about the Digitalmars-d-learn mailing list