On Thursday, 2 August 2018 at 02:52:44 UTC, Hakan Aras wrote:
LDC complains about the type of initializer though:
onlineapp.d(22): Error: Global variable type does not match
previous declaration with same mangled name:
_D5bclib3Baz6__initZ
onlineapp.d(22): Previous IR type: %bclib.Baz = type {
[1 x i8*]*, i32 }
onlineapp.d(22): New IR type: %bclib.BazInitializer
= type { [1 x i8*]*, i32, [4 x i8] }
Any ideas on how to match the type exactly? I don't quite
understand why there are 4 bytes at the back of BazInitializer.
Those 4 bytes for the struct is trailing padding, so that the
struct is 16 bytes large, a multiple of its 8-bytes alignment
(due to the pointer). Classes on the other hand aren't padded
(they don't need to be, as there are no contiguous arrays of
class instances, just class references).
In this case, you could use `align(1) struct BazInitializer` to
prevent the struct tail padding.