Skip to main content
olezhandr
Associate III
July 11, 2020
Solved

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

  • July 11, 2020
  • 3 replies
  • 2263 views

0693W000001sgpDQAQ.png

This topic has been closed for replies.
Best answer by berendi

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

3 replies

berendi
Principal
July 11, 2020

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.

olezhandr
olezhandrAuthor
Associate III
July 11, 2020

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

berendi
Principal
July 11, 2020

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
olezhandrAuthor
Associate III
July 11, 2020

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

berendi
berendiBest answer
Principal
July 12, 2020

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