There's a strange C-language problem:
Char t=0; Char i=0; for (i=0; i < (T-1); i++) { printf ("i=%u\n", i); if - ) break; }
This loop does not execute once, but if you change the char in the code to int, it loops many times.
Because if T is unsigned
char (U8), 1 is an int, t-1 is converted to an int type operation, -1.i is a U8 type, and int is converted to int when compared to int., so 0<-1, the loop will not execute.
If T is unsigned
Int (u32), 1 is an int, and t-1 is converted to a u32 type of operation, which is a large value. I is also the u32 type, so 0<4294967295, the loop executes very many times.
Later in C + +
On the Primer book, find out about type conversions:
The simplest conversion is an integral type: for all integers smaller than int, including char,signed char,unsigned
Char,short and unsigned short, if all possible values of the type can be included in int, they will be promoted to int, otherwise they will be promoted to unsigned
int type. If the bool value is promoted to int, false is converted to 0, and true is converted to 1.
For the inclusion of signed and unsigned
An expression of type int, whose conversion might surprise us. The signed type value in the expression is converted to the unsigned type.
Reprinted from: http://blog.sina.com.cn/s/blog_4a24ee3e01016m8a.html
The problem of judging the unsigned condition of c++:for cycle