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

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Dec 29 17:45:50 UTC 2020


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.
This is because unittest blocks are compiled as if they were functions,
and struct declarations in a function do acquire context pointers.


--T


More information about the Digitalmars-d-learn mailing list