...
The type of the expression (bits.a << 24)
is compiler dependent and may be either signed or unsigned depending on the compiler's interpretation of the standard.
...
The second interpretation is that this (bits.a
is an 8-bit integer. As a result, this eight bit value can be represented as an int
, so integer promotions require that it be converted to int
, and hence "signed". In the signed case, the 24-bit left shift tries to compute 0xFF000000
. For implementations where int is only 32 bits wide, 0xFF000000 > INT_MAX
and the overflow produces undefined behavior (See C99 Sections 3.4.3p3 (non-normative example), 6.5p5 (normative), and 6.5.7p4 (normative)).
...