Take a simple 4-bit integer example, where a = 5 and b = 6. Each binary representation will be
a = 0101 b = 0110
Now, when we subtract them (or take two additions to b, sum with a and add 1), we get the following
0101 1001 + 1 ----- 1111
1111 is equal to 15 (unsigned) or -1 (signed, translated again using two additions). By casting two unsigned numbers, we guarantee that if b> a, the difference between them will be a large unsigned number and will have the highest bit. When translating this large unsigned number into its signed counterpart, we will always receive a negative number due to the established MSB.
As nos pointed out, when the sequence number wraps from the maximum unsigned value back to min, the macro also returns that the maximum value is <min using the above arithmetic, hence its usefulness.
source share