Re: Small structs: interfacing with C++ potentially broken

2021-12-20 Thread Jan via Digitalmars-d-learn
On Monday, 20 December 2021 at 11:58:03 UTC, Tim wrote: On Monday, 20 December 2021 at 10:24:00 UTC, Jan wrote: Is this a known issue, or is there a way to instruct DMD to use a specific calling convention for a given type? This looks like a bug. It seems to work without constructor in C++,

Small structs: interfacing with C++ potentially broken

2021-12-20 Thread Jan via Digitalmars-d-learn
I have a small struct that I'm trying to interface to. C++ ```cpp struct __declspec(dllexport) SmallStruct { float value = 0; //float value2 = 0; //float value3 = 0; SmallStruct(float val) : value(val) { } static SmallStruct GetValue(float input) { return

Re: How to pass a class by (const) reference to C++

2021-12-16 Thread Jan via Digitalmars-d-learn
On Thursday, 16 December 2021 at 16:21:30 UTC, Tim wrote: That looks like another bug in the compiler. pragma(mangle, ...) should work as a workaround. Another bug ticket it is then: https://issues.dlang.org/show_bug.cgi?id=22604

Re: How to pass a class by (const) reference to C++

2021-12-16 Thread Jan via Digitalmars-d-learn
On Wednesday, 15 December 2021 at 22:50:38 UTC, Tim wrote: On Wednesday, 15 December 2021 at 22:46:01 UTC, Jan wrote: Btw. should I report this issue somewhere? Is far as I see this isn't logged yet: Yes, it should

Re: How to pass a class by (const) reference to C++

2021-12-15 Thread Jan via Digitalmars-d-learn
On Wednesday, 15 December 2021 at 22:50:38 UTC, Tim wrote: On Wednesday, 15 December 2021 at 22:46:01 UTC, Jan wrote: Btw. should I report this issue somewhere? Is far as I see this isn't logged yet: Yes, it should

Re: How to pass a class by (const) reference to C++

2021-12-15 Thread Jan via Digitalmars-d-learn
On Wednesday, 15 December 2021 at 22:33:15 UTC, Tim wrote: I agree that __gshared should imply static. That's probably a bug in the compiler. Using `extern` without `export` would only work with static linking (on Windows). `export` without `extern` would be exporting the variable for

Re: How to pass a class by (const) reference to C++

2021-12-15 Thread Jan via Digitalmars-d-learn
On Wednesday, 15 December 2021 at 21:30:47 UTC, Tim wrote: It seems to work if var is additionally static: Ha, it works indeed! ```cpp extern export __gshared static int var; ``` That's a declaration worthy of C++ ! Fewer keywords would be too usable :D Joking aside, I understood the docs

Re: How to pass a class by (const) reference to C++

2021-12-15 Thread Jan via Digitalmars-d-learn
On Wednesday, 15 December 2021 at 17:10:51 UTC, Tim wrote: Do you have a test case for your problem? C++ ```cpp class Test { public: __declspec(dllexport) static int var; }; int Test::var = 42; ``` D ```cpp extern(C++, class) struct Test { extern (C++) export extern __gshared int var; }

Re: How to pass a class by (const) reference to C++

2021-12-15 Thread Jan via Digitalmars-d-learn
On Wednesday, 15 December 2021 at 12:36:49 UTC, evilrat wrote: You probably know this but just in case - unlike C++ in D variables by default have thread local storage, to link with C++ global variable you need to use __gshared storage modifier in D, it is similar to 'shared' variable that

Re: How to pass a class by (const) reference to C++

2021-12-15 Thread Jan via Digitalmars-d-learn
On Wednesday, 15 December 2021 at 11:03:27 UTC, rikki cattermole wrote: On 15/12/2021 11:54 PM, Jan wrote: On Wednesday, 15 December 2021 at 09:36:54 UTC, Jan wrote: Unfortunately it's the "annoying little details" that I immediately bumped into. Just another example: I just learned that

Re: How to pass a class by (const) reference to C++

2021-12-15 Thread Jan via Digitalmars-d-learn
On Wednesday, 15 December 2021 at 09:36:54 UTC, Jan wrote: Unfortunately it's the "annoying little details" that I immediately bumped into. Just another example: I just learned that linking against C++ DLLs is quite limited. I ran into the issue that linking in an external variable doesn't

Re: How to pass a class by (const) reference to C++

2021-12-15 Thread Jan via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 07:50:48 UTC, evilrat wrote: There is some missing features like above tail ref and const, there is minor mangling issues that requires pragma mangle sometimes, and other annoying little details. As far as I can tell from my limited experience, the way D

Re: How to pass a class by (const) reference to C++

2021-12-13 Thread Jan via Digitalmars-d-learn
On Monday, 13 December 2021 at 12:16:03 UTC, Ola Fosheim Grøstad wrote: On Monday, 13 December 2021 at 12:08:30 UTC, evilrat wrote: Yeah but it sucks to have making C++ wrapper just for this. I think either pragma mangle to hammer it in place or helper dummy struct with class layout that

Re: How to pass a class by (const) reference to C++

2021-12-13 Thread Jan via Digitalmars-d-learn
On Monday, 13 December 2021 at 16:29:12 UTC, Tim wrote: I made a pull request, which changes the mangling to tail const for classes passed directly as parameter or return type, but now think this would break too much code: https://github.com/dlang/dmd/pull/13369 The proposal to add a

Re: How to pass a class by (const) reference to C++

2021-12-13 Thread Jan via Digitalmars-d-learn
On Monday, 13 December 2021 at 13:02:50 UTC, Ola Fosheim Grøstad wrote: On Monday, 13 December 2021 at 12:51:17 UTC, evilrat wrote: That example is still looks very conspicuous because it is very likely does nothing on the caller side in C++ as it passes a copy. Yes, I wouldn't want to use

Re: How to pass a class by (const) reference to C++

2021-12-13 Thread Jan via Digitalmars-d-learn
On Monday, 13 December 2021 at 07:48:34 UTC, evilrat wrote: On Sunday, 12 December 2021 at 21:24:39 UTC, Jan wrote: In D I have an extern(C++) class: ```cpp extern(C++) class A { ~this(); // other stuff } ``` An a function that takes A by const reference: ```cpp void CppFunc(const

How to pass a class by (const) reference to C++

2021-12-12 Thread Jan via Digitalmars-d-learn
In D I have an extern(C++) class: ```cpp extern(C++) class A { ~this(); // other stuff } ``` An a function that takes A by const reference: ```cpp void CppFunc(const A& arg); ``` But how do I bind this in D ? ```cpp extern(C++) void CppFunc(A arg); // tries to pass as 'A*'

Re: C++ bindings: const(T) dropped in return types of templates ?

2021-12-09 Thread Jan via Digitalmars-d-learn
On Thursday, 9 December 2021 at 07:58:46 UTC, frame wrote: On Thursday, 9 December 2021 at 07:41:32 UTC, frame wrote: On Monday, 6 December 2021 at 20:31:47 UTC, Jan wrote: So am I missing something, or did the compiler somehow forget about the const-ness? Sounds like a bug to me, eg this

C++ bindings: const(T) dropped in return types of templates ?

2021-12-06 Thread Jan via Digitalmars-d-learn
I am trying to auto-generate bindings for C++ code in D. I've come across something that looks like a bug in DMD to me, but since I'm such a newbie in D maybe I am missing something. My C++ class looks like this: ```cpp template struct Vec3Template { static const Vec3Template ZeroVector();

Re: C++/D class interop example crashes

2021-03-27 Thread Jan via Digitalmars-d-learn
On Saturday, 27 March 2021 at 18:39:53 UTC, Bastiaan Veelo wrote: The example links objects statically. You may be experiencing additional challenges with crossing DLL boundaries. I have not yet used DLLs, but did you initialise the D runtime? I haven't done anything extra (I'm pretty new to

C++/D class interop example crashes

2021-03-27 Thread Jan via Digitalmars-d-learn
I just tried to get this example to work: https://dlang.org/spec/cpp_interface.html#using_d_classes_from_cpp It kept crashing for me with a 'privileged instruction' error when the function 'bar' was executed. Finally I removed the call to writefln and voilà it finally works. So why does it

Re: Mimicking a shell

2020-01-06 Thread Jan via Digitalmars-d-learn
I think the suggestion of angel would be most fitting for my case. As angel said, the using the C code for D would be a relatively small refactor. if you want to send like a synthetic arrow keystroke, well, things get ugly again, it will need to send the right series of bytes based on what

Re: Mimicking a shell

2020-01-04 Thread Jan via Digitalmars-d-learn
On Sunday, 29 December 2019 at 19:21:53 UTC, Adam D. Ruppe wrote: On Sunday, 29 December 2019 at 17:03:14 UTC, Jan wrote: Is there a way to forward all input and output from a shell? yes, but it is platform specific and can be a decent amount of code. what OS are you on? I am using Linux

Mimicking a shell

2019-12-29 Thread Jan via Digitalmars-d-learn
Hi, Is there a way to forward all input and output from a shell? This implies that e.g. pressing the left arrow on the keyboard is immediately being forwarded to the shell and that the output from a shell would be *exactly* the same as output from my D program (that would include the prompt

Re: Pass 'this' as reference

2018-09-19 Thread Jan via Digitalmars-d-learn
On Saturday, 15 September 2018 at 20:13:51 UTC, Jonathan M Davis wrote: On Saturday, September 15, 2018 11:44:05 AM MDT Jan via Digitalmars-d-learn wrote: [...] No. variables are _always_ lvalues. An lvalue is an object which is addressable and which can therefore be assigned a value

Re: Pass 'this' as reference

2018-09-15 Thread Jan via Digitalmars-d-learn
On Thursday, 13 September 2018 at 11:08:30 UTC, Jonathan M Davis wrote: [...] Thanks for clarifying Jonathan :) But aren't the variables considered rvalues then?

Re: Pass 'this' as reference

2018-09-13 Thread Jan via Digitalmars-d-learn
Many thanks Adam and Steve! Works like a charm! :D I presumed classes are lvalues. I shouldn't make things more complicated than they are ;-)

Pass 'this' as reference

2018-09-12 Thread Jan via Digitalmars-d-learn
I'm using D not for that long and lately I have encountered an issue. I have class 'Foo' with a constructor using this signature: `this (ref Bar original)` In the 'Bar' class itself I want to create an instance of 'Foo' using 'this' as parameter. Something in the way of: `Foo foo = new