Interfacing to C++: Cannot access value from namespace

Ali Çehreli acehreli at yahoo.com
Sat Sep 7 12:39:25 UTC 2019


On 09/07/2019 03:26 AM, Andrew Edwards wrote:

 > [1] I did not declare any of the other member variables from the struct,
 > don't know if this is a source of the problem.

Yes, it definitely is a problem. The members are accessed as byte 
offsets into their objects. Without defining the other members, your 
D-side member is read from offset 0, which is not the case on the C++ side.

However, I'm still not sure whether that would solve the problem due to 
the following differences between C++ and D:

- No 'volatile' keyword in D (not in your example code anyway)

- Variables are thread-local by default in D

But I guess extern(C++) takes care of those differences. (?) So, it 
should work after defining all the members. :)

Ali



More information about the Digitalmars-d-learn mailing list