August 02, 2018
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.
August 02, 2018
On Thursday, 2 August 2018 at 10:54:17 UTC, kinke wrote:

> 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.

Oh yeah, forgot about alignment. It's no use though. Unless I can get my hands on the internal "struct" type of Baz somehow, LDC is not gonna let me declare it:

https://github.com/ldc-developers/ldc/blob/69104bdbf94713431cbc67151c1b34a6a5e0df34/gen/llvmhelpers.cpp#L1759
1 2
Next ›   Last »