Assuming your code suffers from shutdown with a single error (the current code stops before the final evaluation). Then the following may answer you.
Very simple, since your counter is a 16-bit unsigned integer, it cannot have a value greater than 0xffff , since this value is still valid, you need to have some value that goes beyond the scope of this parameter as a defender. However, adding 1 to 0xffff in 16 bits just wraps around to 0 . As suggested, use a do while loop (which does not require a protective value) or use a larger value to contain your counter.
ps. Using 16-bit variables on modern machines is actually less efficient than using 32-bit variables, since there is no need to generate overflow code.
Paul de vrieze
source share