It may be more useful to have an uncontrived example of what this is good for. (I say "uncontrived" because most bit-banging uses of union are extremely treacherous. Bit-banging unions taken from big-endian to little-endian hardware break in the most (initially) mystifying ways.) (Of course, I've written bit-banging unions to tear apart floating point numbers to implement orders-of-magnitude-faster-than-the-library math functions. I just add assertions about which members are supposed to have the same addresses.)
struct option1 { int type; /* other members */ };
struct option2 { int type; /* other members */ };
struct option3 { int type; /* other members */ };
union combo {
int type; // guaranteed to exactly overlap with the structs' ints type.
struct option1;
struct option2;
struct option3;
};
// ...
void foo(union combo *in) {
switch(in.type) {
case 1: { struct option1 *bar = in; //then process an option1 type of request }
case 2: { struct option2 *bar = in; //then process an option2 type of request }
case 3: { struct option3 *bar = in; //then process an option3 type of request }
}
This kind of construction is very common in X programming and other situations where one wishes to make a function that can receive many different types of messages (with different argument and layout requirements).