News for hackers. Stuff that matters.
Re:20 bit operations programmers should know by ambrop7 on Saturday June 08, 2013 @08:48AM (#5844744)
1.1, 1.2, 17.1: wrong, signed integer overflow

1.3, 2.2: wrong, shifting by negative number is undefined behavior

2.1: wrong, relies on some specific behavior for signed integer overflow

4, 5, 6, 7, 10, 11, 12, 17.1, 18: wrong, shifting negative numbers is implementation-defined behavior

Some examples will also suffer from integer overflow if the type 'int' is changed to something bigger (because then 1<<n could overflow, you'd need .e.g (uint64_t)1<<n).

There are no comments on this comment yet.