iharob
's answer is of course correct, but I think that it is also important to know how to avoid this kind of errors in the future.
I have also have not found any explicit reference of this behavior (implicit cast from a "large" numeric type to a "smaller" one), so I have asked a question about this.
Shortly put, by providing the correct compilation warning flags, these errors can be spotted at compile time (e.g. -Wconversion
), as it's almost always a bug.
However, this behavior is by design, and as mentioned by Chris in a comment, sometimes it might be useful in terms of performance.