2020-07-11 01:11 AM
2020-07-12 03:51 AM
Yes, this is the effect of integer promotion. Short and char types are converted to signed int every time they are used in an expression. Unsigned shorts are extended with 0 bits (0x81d0 -> 0x000081d0), signed are extended with the value of bit 15 (0x81d0 -> 0xffff81d0).
2020-07-11 02:30 AM
Short is a 16 bit signed integer type in the range from -0x8000 to 0x7fff, so 0x81d0 is out of its range. Therefore the condition is never true.
Read the warnings issued by the compiler, they are there for a reason.
Review the integer types and promotion rules, otherwise you would get a few more surprises with types that are less than 32 bits wide.
2020-07-11 05:45 AM
if I change variable to <C> from <symb> it works corretly but <C> and <symb> are unsigned short type as you can see from my screen
2020-07-11 06:37 AM
C is unsigned, symb is signed.
When neither signed nor unsigned is explicitly stated, then the default is signed. (Except for the char type, where it depends on the compiler configuration and command line options, so you can never be sure.)
2020-07-11 07:09 AM
Thank you! I understand my mistake! I thought that sign store at 15 bit.. but it stored at 31
2020-07-12 03:51 AM
Yes, this is the effect of integer promotion. Short and char types are converted to signed int every time they are used in an expression. Unsigned shorts are extended with 0 bits (0x81d0 -> 0x000081d0), signed are extended with the value of bit 15 (0x81d0 -> 0xffff81d0).