Nasty supprise when using c 'anonymous struct and union' in D with 'static struct'

Steven Schveighoffer schveiguy at gmail.com
Tue Dec 29 17:50:06 UTC 2020


On 12/29/20 12:45 PM, H. S. Teoh wrote:
> On Tue, Dec 29, 2020 at 05:13:19PM +0000, Arjan via Digitalmars-d-learn wrote:
> [...]
>> On the C/C++ side there is no static. I added those on the D side to
>> to make sure there is no context pointer being added, since that will
>> change the layout and size of struct. (in the c/c++ code those unions
>> and structs are nested several levels deep)
> 
> You need to add 'static' to the (outer) struct declarations in your
> unittest block, because otherwise they *will* have a context pointer.

Not if the struct is POD. And in this case, they are all POD (no methods).

-Steve


More information about the Digitalmars-d-learn mailing list