In Visual C++ 2012 the code
double d = 0.5;
float f = d;
int i = f;
issues 2 warnings for me:
test.cpp(26): warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
test.cpp(27): warning C4244: 'initializing' : conversion from 'float' to 'int', possible loss of data
I want to suppress the first warning which I consider spam, but keep the second warning which I consider very helpful. Is it possible to suppress the one and keep the other? Do people generally just suppress them all? We had a bad bug where we mistakenly passed a double to a float. But we tons of our math code would trigger the double->float warnings.
Don't suppress warnings that are designed to prevent potential bugs. Tell the compiler you know what you are doing instead by casting:
double d = 0.5;
float f = static_cast<float>(d);
int i = static_cast<int>(f);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With