I try to search an answer to my question... What is the type of this expression will be at C language?
unsigned short a, b;
a = 0x1;
b = 0x2;
if((a ^ b) > 0) //This expression...
...
I understand that this is not a completely correct code that can cause an error. I should use != instead >.
I think that the type of the result of the expression will be unsigned int. I read about it in Stephen Pratt’s book.
If we have two types, then the result of an expression involving these types must be a superior type. (int or unsigned int)
If these two variables have any other values, can it be that this expression will be less than zero? (If we set the most significant bit in the number, it will become negative, provided that it has signed data type)
I think it is impossible, but I could be wrong. I made my guess, but I want to know the correct answer to my question.
INT_MAX
is smaller thanUSHORT_MAX
, the expression will be of typeint
. Hence, to have a minimal reproducible example, you need to post the relevant values fromlimits.h
. – EOF May 29 '19 at 20:10unsigned short
can hold is not0xFFFF
, it'sUSHRT_MAX
, which has an implementation defined value no smaller than65535
. Consequently, the value can be larger. Moreover, the value ofINT_MAX
is also implementation defined and may be as low as32767
. – EOF May 29 '19 at 20:22a ^ b
,(a ^ b)
,(a ^ b) > 0
, or something else? – Eric Postpischil May 29 '19 at 20:30