How to print untagged union?

const U = extern union {
   foo: [10]u8,
   bar: u32
};


const u = U{.bar = 1};

// How can I know which field is available and print it?

extern union is C ABI compatible. C unions are not tagged and there is no way to know which member is active, only from the union data.

switch statement can be used to select the active tag from tagged unions

3 Likes