[ub] signed left shifts again

John Regehr regehr at cs.utah.edu
Thu Nov 14 00:26:08 CET 2013


> I have not seen the examples, but is it not the case that casting to unsigned
> before the shifts would have created defined behavior?

Yes, all of the undefined behaviors due to LHS of shifts would go away 
with appropriate casts.  I imagine that people just don't realize these 
are necessary.

The bulk of the UBs were due to promotion of unsigned char to int.  A 
minority were due to variables that were declared as signed types in the 
first place -- not a good idea, as you remarked earlier.

John



More information about the ub mailing list