summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
beba02c)
shifting more than the number of bits in the type yields undefined results.
// Same as l >> (8 * sizeof l), but without the warnings
T sign = l < 0 ? ~0 : 0;
// Same as l >> (8 * sizeof l), but without the warnings
T sign = l < 0 ? ~0 : 0;
- while ((l >> (8 * c)) != sign) {
+
+ T sl = l;
+ unsigned c = 0;
+ do {
+ } while (sl >>= 8 != sign);
+
// Add an extra byte if sign bit doesn't match
if (((l >> (8 * c - 1)) & 1) != ((l >> (8 * sizeof l - 1)) & 1)) {
++c;
// Add an extra byte if sign bit doesn't match
if (((l >> (8 * c - 1)) & 1) != ((l >> (8 * sizeof l - 1)) & 1)) {
++c;