Possible Duplicate:
g++ -Wall not warning about double-> int cast
Per the question here, direct conversion from double/float to unsigned integer is not portable. I found I had a few cases in my code where this happens and I would like to tell g++ to warn me if this occurs, but I can't find such an option. Does anyone know if there is an option to do this?
Note: I do see -Wconversion, but that also warns about all kinds of other conversions that I don't care about (like converting int to unsigned int, which is portable per the standard).
Edit: Here's a code example for which I would like to see a warning:
double dblNumber = -234;
unsigned long uintNumber = dblNumber;
On one version of g++, this gives me an integer value of 0xFFFFFF16 (which is -234 in 2's complement) . On another it gives me 0. Clearly the code is ambiguous, which is why it is understandably not considered portable.
un_signed_int_value=(unsigned int) double_value;
you are telling the compiler I know what I am doing. So I don't see why compiler would warn about such conversions. In fact, the explicit cast would suppress any warnings if there was one. Unless I misunderstood your question, what you are asking is not possible.-Wconversion
doesn't detect this, I can't think of anything else on how the conversion is done.