关于:有符号与无符号整数的大小比较

引子:

Qt:  

QArray  array;

array.append(0x81);

array.at(0) == 0x81 ?   : false 

例子:

char                       t1                =0x01;

unsigned  char       t2               =0x01;

t1== t2      ?      : true

//-----------------------------------------------------

char                       t1                =0x81;

unsigned  char       t2               =0x81;

t1== t2      ?      : false

//-------------------------------------------------------

short                       t1                =0x8001;

unsigned  short      t2                   =0x8001;

t1== t2      ?      : false

这里有个隐含的问题: 就是数据范围溢出。

所以在对数据做比较的时候  还是以相同类型为原则,同时也要避免隐式转换。

类比Golang  语言的数据比较同类型原则、强制级别更高,还是有现实意义的。

原文地址:https://www.cnblogs.com/Esperanto/p/7527017.html