uint16_t sometimes overflow in 255
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2017-09-24 3:19 PM
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 discussion is locked. Please start a new topic to ask your question.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2017-09-24 4:21 PM
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..
Up vote any posts that you find helpful, it shows what's working..
