In the CR question "Terminating a C loop when maximum hardware limit reached" the use of a positive sum wrapping to a negative value is used to terminate the loop. The queston was posted to Code Review even though it could reasonably been asked on Stack Overflow instead. The responses have provoked another question:
When
fib
is less than the max integer value supportedprev
is also well less than the max integer supported. So, the sum of the two will never exceed the integer size so as to overflow beyond a negative range. The use of the testfib>0
will work in the special case of the Fibonacci numbers but does not generalize. What code would be a better solution for the more general case?
Which is the better fit for the question, Code Review or Stack Overflow?
1 Answer 1
Hmm. The rule of thumb I use for Code Review is:
It is working, functional code with no (obvious to the author, anyway) errors
You want aesthetic and subjective peer feedback on this working, functional code
Seems to me this question could go either way?
You must log in to answer this question.
Explore related questions
See similar questions with these tags.