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

Daniel Green venix1 at gmail.com
Mon Sep 3 08:52:50 PDT 2012


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 consideration and the compiler is optimizing access to this.

However, I would imagine that such optimizations would not be allowed 
with C++ and so by using a class it requires a pointer type and not the 
optimized struct.

The following returns the value of 4 when I inspect the variable 
refValue instead of the correct address and segfaults.

http://codepad.org/eepFTfbX


More information about the D.gnu mailing list