Gabriel Sechan wrote:
Would this be correct?
"""
#include <limits.h>
...
if (libretval_x & INT_MAX < mysigned_x)
do something..
"""
Platform specific- INT_MAX doesn't have to be 011111....1111. It can be all 0's, if the platform is braindead. So that's undecidable without more knowledge.
In general, with bitwise operators, you need to be sure about the
bitwise layout of your types. It does seem odd to use INT_MAX instead of
(~0) for a mask, but who knows what the intent is.
This is a case where you'd have to cast one or the other's values to change the
sign. Usually you cast the signed to unsigned, but that's a style thing. Most
compilers take an explicit cast to be always correct, and won't generate a
warning.
Really, the above logic seems odd, but it is really hard to know what is
wrong or right about it without more information. It certainly seems
like an odd bit of code.
--Chris
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg