On Mon, Aug 28, 2017 at 10:54:07PM +0200, Martin Eberhard Schauer wrote: > > > Well, casting to long helped - but in how far does making > > > > abs(unsigned - unsigned) > > > > no sense? This does not sound very logical to me. > > > The result of (unsigned - unsigned) is unsigned. > What about A, B both unsigned and B > A?
None of A,B and result will be promoted to a signed type, so you'll get an integer underflow. example (for a 32 bit type) 0x1-0x2 = 0xFFFFFFFF = 2^31-1 As the compiler knows that the type is unsigned, abs()'d be a noop.