The test code:
struct A
{
uint32_t lo : 16;
uint32_t hi : 16;
};
int main()
{
A a{};
a.lo = 0xFFFF;
auto b = a.lo << 16;
cout << b << endl;
return 0;
}
The output is:-65536, and the type of b is int but not uint32_t.
I have found that, uint16_t and uint8_t will also become signed int after shift operator, and there was a similar question in C#, which came to the conclusion that the result would become signed when the operand is <32 bits.
Why do shift operations always result in a signed int when operand is <32 bits
But the type of a.lo is clearly uint32_t, which can be verified by decltype(a.lo), so how can this be explained?