In the C language these two operations have different semantics:
If x is 8bit type, then right x in the first operation is promoted to int, while in the second one there is 8-bit shift. Clang gives a warning in the second case.
x = x >> 8;
x >>= 8;If x is 8bit type, then right x in the first operation is promoted to int, while in the second one there is 8-bit shift. Clang gives a warning in the second case.
("The New C Standard. An Economic and
ReplyDeleteCultural Commentary.", v1.2, page617) к footnote 48 из стандарта С99:
> > 48) The integer promotions are applied only: as part of the usual arithmetic
> > conversions, to certain argument expressions, to the operands of the
> > unary +, -, and ~ operators, and to both operands of the shift operators,
> > as specified by their respective subclauses.
> > Commentary
> > ...
> > Contexts where the integer promotions are not applied are ...
> > the operands of the assignment operator,
> > ...
> > The value is, potentially, implicitly cast directly to the destination type.