cancel
Showing results for 
Search instead for 
Did you mean: 

Hi everyone! STM32CubeIDE: debuger skip comparison with constant, stlink + stm32F429. Why and how to fix?

olezhandr
Associate III
1 ACCEPTED SOLUTION

Accepted Solutions
berendi
Principal

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).

View solution in original post

5 REPLIES 5
berendi
Principal

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.

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

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.)

olezhandr
Associate III

Thank you! I understand my mistake! I thought that sign store at 15 bit.. but it stored at 31

berendi
Principal

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).