I'm getting a (expected)
warning: large integer implicitly truncated to unsigned type [
-Woverflow
]
on Get2()
but on not on Get1()
. I'm quite puzzled why:
#include <stdint.h>
uint8_t Get1()
{
return uint8_t(uint64_t(10000));
}
uint8_t Get2()
{
return uint64_t(10000);
}
int main()
{
return 0;
}
This is a simplified version of some templated code doing other things - without hard-coded values. The same happens in C++ when compiled either with GCC or Clang.
The warning, which is reported on the
Get2
function, is there because there's an implicit conversion (as opposed to the explicit one you have onGet1
) happening, and the compiler is warning you that the integer is being truncated.The explicit one is not being reported, because you have explicitly told the compiler that you are performing a truncation, so a warning would probably be redundant in that case.