News for hackers. Stuff that matters.
Re:Switching from C++ to Rust by planede on Tuesday March 14, 2023 @07:30AM (#35149869)
C++ allows accessing inactive members in the special case when the active member shares a "common initial sequence" with the particular inactive member.

So yeah, it's possible to store the tag in the common initial sequence of all the union members.

This is quite niche and rarely used. Most of the time it makes more sense to have the tag outside. Sometimes the tag in the common initial sequence allows the whole data structure to pack better than with a tag outside of the union.

There are no comments on this comment yet.