Skip to main content
Pedram
Associate III
September 24, 2017
Question

uint16_t sometimes overflow in 255

  • September 24, 2017
  • 1 reply
  • 605 views
Posted on September 25, 2017 at 00:19

Hello friends

I defined a variable uint16_t x;

in my code I will compare x >= 500 Most of the time works fine

But sometimes variable is Overflow in 256 i see in debug 

variable is 0 after 255+1

i using IAR , STM32F103ZET6 , HAL

How can I fix this?

Thank

    This topic has been closed for replies.

    1 reply

    Tesla DeLorean
    Guru
    September 24, 2017
    Posted on September 25, 2017 at 01:21

    Are you looking at bytes in memory or words? 256 would appear as consecutive bytes 0x00 0x01

    May be you can actually show an example of the code, and the state in the debugger?

    The value could get constrained if you cast it through a char or uint8_t

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..