Re: Trouble understanding crash when class is returned by value from C++

2012-09-03 Thread Iain Buclaw
On 3 September 2012 18:15, Andrej Mitrovic wrote: > On 9/3/12, Iain Buclaw wrote: >> Indeed, C++ classes are always passed in memory by design. Whereas > pointers could be passed in registers. > > That's cool. I learn something new every day. :) > >> And this is one >> reason why you need to en

Re: Trouble understanding crash when class is returned by value from C++

2012-09-03 Thread Andrej Mitrovic
On 9/3/12, Iain Buclaw wrote: > Indeed, C++ classes are always passed in memory by design. Whereas pointers could be passed in registers. That's cool. I learn something new every day. :) > And this is one > reason why you need to ensure that function signatures match in both D > and C/C++ code

Re: Trouble understanding crash when class is returned by value from C++

2012-09-03 Thread Iain Buclaw
On 3 September 2012 16:52, Daniel Green wrote: > My best guess, is the issue is related to the struct being 4 bytes. > A similar segfault occurs if you attempt to access in a similar manner using > c++. > > A 4 byte struct will fit into a single register making pointers > unnecessary/slower and it

Re: Trouble understanding crash when class is returned by value from C++

2012-09-03 Thread Daniel Green
My best guess, is the issue is related to the struct being 4 bytes. A similar segfault occurs if you attempt to access in a similar manner using c++. A 4 byte struct will fit into a single register making pointers unnecessary/slower and it's likely some part of the ABI has taken this into con

Trouble understanding crash when class is returned by value from C++

2012-09-02 Thread Andrej Mitrovic
I'm trying to add at least *some* type of pass-by-value support for C++ classes when wrapping C++ libraries to D. I figured I could fake a value class by using a D struct with a thunk field which matches the size of the C++ object. Returning a C++ object by value works in this plain C++ example (u