unsigned type is dangerous

google的tcmalloc代码里面有这样一段warning:

// NOTE: unsigned types are DANGEROUS in loops and other arithmetical

// places. Use the signed types unless your variable represents a bit
// pattern (eg a hash value) or you really need the extra bit. Do NOT
// use 'unsigned' to express "this value should always be positive";

// use assertions for this.


尽管一直知道这个,可就老是情不自禁的使用unsigned,太二了!

以后除非万不得已,肯定不用了。

你可能感兴趣的:(unsigned type is dangerous)