You seem to be confusing 2 different questions: coding for something and the meaning of something . Here is an example: you see the number 97. This is a decimal encoding. But the meaning of this number is something completely different. It can denote the ASCII 'a' symbol, very hot temperature, geometric angle in a triangle, etc. You cannot deduce the value from the encoding. Someone should provide you with a context (e.g. ASCII map, temperature, etc.).
Back to your question: 0x80000000 is encoding. While INT_MIN matters. They are not interchangeable and not comparable. On certain equipment, in some contexts, they can be equal, like 97, and "a" are equal in the ASCII context.
The compiler warns you of ambiguity in value, not in encoding. One way to give meaning to a particular encoding is to cast a statement. Like (unsigned short)-17 or (student*)ptr;
In a 32-bit system or 64 bits with backward compatibility of int and unsigned int there is a 32-bit encoding, as in 0x80000000 , but for 64 bits MIN_INT will not be equal to this number.
In any case, the answer to your question is: to remove the warning, you must give an identical context to both the left and right comparison expressions. You can do this in many ways. For instance:
(unsigned int)a == (unsigned int)0x80000000 or (__int64)a == (__int64)0x80000000 or even crazy (char *)a == (char *)0x80000000 or in any other way if you observe the following rules:
- You do not lower the encoding level (do not reduce the number of bits that are required). Like
(char)a == (char)0x80000000 is incorrect, because you reduce 32 bits by 8 bits - You must specify both the left and right sides of the == operator in the same context. For example, as
(char *)a == (unsigned short)0x80000000 is incorrect, an error / warning message is issued.
I want to give you another example of how important the difference between coding and value is. Look at the code
char a = -7; bool b = (a==-7) ? true : false;
What is the result of 'b' ? The answer is shocking: it is undefined. Some compilers (usually Microsoft visual studio) will compile a program in which b will get true , while on Android compilers NDK b will get false . The reason is that the Android NDK treats the type char as an unsigned char , and Visual Studio treats the char as a signed char . So, on Android phones, the encoding -7 actually has a value of 249 and is not equal to the value (int) -7. The correct way to fix this problem is to define "a" as a signed char:
signed char a = -7; bool b = (a==-7) ? true : false;