On Saturday, 11 April 2026 at 06:56:36 UTC, Danni Coy wrote:
ok gets weirder - adding an int to the beginning of the anonymous union removes the linker problem.

union
{
     int _;
    EventA a;
    EventB b;
}

Is this a bug, or is there something I am missing?

Most likely `EventA` has an .init value that isn't all 0. When it becomes part of a struct or the first member of a union, that also makes the enclosing struct have a non-zero .init symbol which you must link when you want to use it. Either make `EventA` a zero initialized type (you can check with `__traits(isZeroInit, EventA)`) or override the default init value, like `EventA a = 0;` or `EventA a = void;`.

Or just ensure that every module you import also gets compiled into the final executable. Sometimes you can get away with 'header only' imports, but it's bound to bring up subtle issues like this so it's best to just include everything either using the `-i` switch or by listing every file yourself.

Reply via email to