This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

signed, unsigned integer and wrap



Hi,

I read the following from the C6000 hand tune loops for C6000. Does it mean signed integers not wrap around?

unsigned integer is wrap around? Could you explain it to me?

Thanks,

 

 

..............

Make sure index variables are signed integers. This communicates to the compiler that

increments are linear (do not wrap around). This includes index variables used to do

counting in loops. It also includes index variables used for subscripting. When the compiler

knows that index variables are linear, there are more opportunities for optimization.

  • The C standard guarantees that unsigned integers wrap around on overflow, as you expect.  However, the C standard explicitly says that signed integer overflow is undefined behavior, which means that it is illegal to write code which has signed integer overflow.  The compiler may do anything with code that has signed integer overflow, such as generate a random value, crash, or possibly even do what you expected.  The TI compiler takes advantage of this freedom to optimize loops with signed integer control variables by assuming that the loop will not iterate so many times that the signed integer would overflow.