@davewill: No. Left shift and right shift are undefined when the value is negative. Your example might work on x86 (because it bitmasks the right operand) but might not work on ARM.
return (a - b) ^ (int)((0 - ((a ^ b ^ (a - b)) >> ((sizeof(T) << 3) - 1))));
Would be more generic - assuming of course that you have 8-bit bytes ![]()