A union is a user-defined type whose members overlay one object representation instead of forming a larger object. Each member offers a different type interpretation of the same storage. section 12.2
Inspecting an unsigned value byte by byte
Define a union containing an unsigned value and an unsigned-char array sized with sizeof(unsigned). Initialize val to 0xAABBCCDD, then print val and each bytes element. One observed machine prints DD, CC, BB, AA: the low-order representation digit appears first. This byte order is implementation-defined, not normalized by the C standard. section 12.2
typedef union unsignedInspect unsignedInspect;
union unsignedInspect {
unsigned val;
unsigned char bytes[sizeof(unsigned)];
};
unsignedInspect twofold = { .val = 0xAABBCCDD, };
Use the union declaration and initializer to inspect the same unsigned object's value view and byte-array view. section 12.2
TAKEAWAY: unions overlay different object types over the same object representation. Viewing an object through unsigned char exposes its representation bytes, but their ordering depends on the implementation. section 12.8 section 12.2









