4 ms·
As a long-time embedded C coder: I agree that (with the added benefit on hindsight) the original code "smells". I'm well-tuned to consider overflows, and addin
by AceJohnny2 5y ago
As a long-time embedded C coder: I agree that (with the added benefit on hindsight) the original code "smells".
I'm well-tuned to consider overflows, and adding numbers together instinctively makes me consider whether there's a risk... Similarly, subtracting numbers should make one consider underflows.
Perhaps the original author was used to working with signed values and forgot to consider the risk of underflow with these unsigned variables.
(I used to have C's type promotion rules on quickdraw, but I very soon learned that if I needed to refer to them, I was probably doing something wrong)