Best way to detect integer overflow

On assignment C-bootcamp1, we were asked to write a factorial function.
The difficult part is how to detect integer overflow.

Defective idea
After some research with Google, I found a post on StackOverflow.com, which guides me to fault. I can’t find the original post though.

It says, when integer overflow occurs, the result(n * (n-1)) is smaller than n.
Because, int, on a 32 bit machine, is 32bits, the return value is truncated when it needs more bits, namely when it is Continue reading “Best way to detect integer overflow”