cancel
Showing results for 
Search instead for 
Did you mean: 

uint16_t sometimes overflow in 255

Pedram
Associate III
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

1 REPLY 1
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 Venmo
Up vote any posts that you find helpful, it shows what's working..