News for hackers. Stuff that matters.
Re:Tagged unions, or ‘variants’, in C by OskarS on Monday June 26, 2017 @09:08AM (#14636446)
I'm not a C programmer, but isn't there some directive you can add to a union to tightly pack it, or specify member memory locations or something? So that then you could guarantee that for the Some struct, `ptrdiff_t tag;` starts at offset 0 and the union starts at offset `sizeof(ptrdiff_t)`?
Re:Tagged unions, or ‘variants’, in C by clarry on Monday June 26, 2017 @09:17AM (#14636525)
That doesn't help if your architecture doesn't support unaligned access.

The compiler is allowed to insert padding for a good reason, and packing is rarely the right solution for anything.