Visual C++ 2017 and gcc 5.4 produce conversion from 'const unsigned char' to 'const float' requires a narrowing conversion
warning for Line B
but not for Line A
in this code snippet:
#include <iostream>
int main() {
const unsigned char p = 13;
const float q = p; // Line A
std::cout << q << '\n';
const unsigned char c[3] = {0, 1, 255};
const float f[3] = {c[2], c[0], c[1]}; // Line B
for (auto x:f)
std::cout << x << '\n';
}
Is this warning valid? Why Line B
is treated differently than Line A
?