The bytes of the object representation for a union that are not also bytes of the object representation of the active member also become unspecified values in C, erasing any trap representations (because unspecified values in C are not trap representations).
It appears C++ is less aggressive with respect to initialized padding bytes in structure and union types.
> It is further an issue that the definition of trap representation does not admit trap representations for the exact-width integer types (int16_t, etc.) because the lack of padding bits, combined with two's complement representation, means that every possible object representation represents a value of the type.
So, C says that uninitialized automatic variables have indeterminate value.
That's fine for some types, because the implementation can choose to use
a trap representation as the particular value used for that case,
which makes any access undefined behavior.
However, this avenue can't be taken for e.g. int16_t, because there are
no bits left for a trap representation to be a possibility.
Yes, for the C++-compatible range of int16_t, there are no bits left for a trap representation to be a possibility.
But it's really helpful for optimizers to assume that uninitialized
automatic variables can't be read.
> I think it would really help if the C committee could record a decision to move towards harmonizing with C++ on this.
Yes. In particular since optimizers are likely to be the same for C and C++, anyway.
Yes, and we're at risk of getting a hodge podge mix of the C and C++ rules in implementations.
Jens