extern __gshared const(char)* symbol fails

Laeeth Isharc Laeeth at laeeth.com
Sun Sep 2 12:40:30 UTC 2018


On Friday, 31 August 2018 at 18:49:26 UTC, James Blachly wrote:
> On Friday, 31 August 2018 at 17:18:58 UTC, Neia Neutuladh wrote:
>> On Friday, 31 August 2018 at 06:20:09 UTC, James Blachly wrote:
>>> Hi all,
>>>
>>> ...
>>>
>>> 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.
>>
>> A bare `extern` means "this symbol is defined somewhere else".
>>
>> `extern(C)` means "this symbol should have C linkage".
>>
>
>
> I am so sorry -- I should have been more clear that this is in 
> the context of a large header-to-D translation .d file, so the 
> whole thing is wrapped in extern(C) via an extern(C): at the 
> top of the file.

In case you weren't aware of it, take a look at atilaneves DPP on 
GitHub or code.dlang.org.  auto translates C headers at build 
time and mostly it just works.  If it doesn't, file an issue and 
in time it will be fixed.




More information about the Digitalmars-d-learn mailing list