digitalmars.D.learn - Interfacing to C++: Cannot access value from namespace
- Andrew Edwards (28/28) Sep 07 2019 I'm running into the following issue when attempting to interface
- =?UTF-8?Q?Ali_=c3=87ehreli?= (4/6) Sep 07 2019 They mean the same thing for an English speaker but compilers don't know...
- Andrew Edwards (4/10) Sep 07 2019 LOL. Sorry about that, I decided to change the variable name in
- Andrew Edwards (4/18) Sep 07 2019 The problem existed prior to this naming mishap and remains after
- =?UTF-8?Q?Ali_=c3=87ehreli?= (11/13) Sep 07 2019 Yes, it definitely is a problem. The members are accessed as byte
- Andrew Edwards (7/17) Sep 07 2019 That was it, and yes it solves the problem. There are far too
I'm running into the following issue when attempting to interface with C++: // C++ ======== namespace MySpace { MyType& GetData(); } struct MyType { // ... float continuallyUpdatedValue; // ... }; // call site MySpace::GetData().continuallyUpdatedValue; // D ======== extern (C++, MySpace) MyType* GetData(); struct MyType { float continuallyChangingValue; // [1] } // call site MySpace.GetData().continuallyUpdatedValue; // <--- This is not being updated by C++ [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.
Sep 07 2019
On 09/07/2019 03:26 AM, Andrew Edwards wrote:float continuallyUpdatedValue; float continuallyChangingValue; // [1]They mean the same thing for an English speaker but compilers don't know that (yet?). :) Ali
Sep 07 2019
On Saturday, 7 September 2019 at 12:24:49 UTC, Ali Çehreli wrote:On 09/07/2019 03:26 AM, Andrew Edwards wrote:LOL. Sorry about that, I decided to change the variable name in the middle of writing the post and missed one. Andrewfloat continuallyUpdatedValue; float continuallyChangingValue; // [1]They mean the same thing for an English speaker but compilers don't know that (yet?). :) Ali
Sep 07 2019
On Saturday, 7 September 2019 at 12:30:53 UTC, Andrew Edwards wrote:On Saturday, 7 September 2019 at 12:24:49 UTC, Ali Çehreli wrote:The problem existed prior to this naming mishap and remains after correcting it.On 09/07/2019 03:26 AM, Andrew Edwards wrote:LOL. Sorry about that, I decided to change the variable name in the middle of writing the post and missed one. Andrewfloat continuallyUpdatedValue; float continuallyChangingValue; // [1]They mean the same thing for an English speaker but compilers don't know that (yet?). :) Ali
Sep 07 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
Sep 07 2019
On Saturday, 7 September 2019 at 12:39:25 UTC, Ali Çehreli wrote:On 09/07/2019 03:26 AM, Andrew Edwards wrote:That was it, and yes it solves the problem. There are far too many variables to define at the moment so I found the offsetof() and defined a "void[offset] pad" to take care of the issue for right now. Thanks, Andrew[1] I did not declare any of the other member variables fromthe 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:
Sep 07 2019