This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

OVERFLOW

HI Can anyone tell me that


 unsigned char time;
 .....
 void interrupt_timer ( void ) interrupt 1
{
   time++;
}

The unsigned char is of 1 byte and has maximum value of 255. So what will happen when the time exceeds 255?

Parents
  • "Behavior on integer overflow is not specified in the C standard, so basically anything could happen."

    Integer overflow behavior is specified in the C standard. Signed integer overflow is specified as "undefined behavior" and about unsigned integer overflow behavior, the standard says:

    "A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type."

Reply
  • "Behavior on integer overflow is not specified in the C standard, so basically anything could happen."

    Integer overflow behavior is specified in the C standard. Signed integer overflow is specified as "undefined behavior" and about unsigned integer overflow behavior, the standard says:

    "A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type."

Children
No data