警告:左移计数> =types的宽度
编译时,我是处理位的新手,遇到以下警告:
7: warning: left shift count >= width of type
我的第7行看起来像这样
 unsigned long int x = 1 << 32; 
 如果在我的系统上的long是32位,这将是有意义的。 但是, sizeof(long)返回8 , CHAR_BIT被定义为8 ,表示long应该是8×8 = 64位长。 
 我在这里错过了什么?  sizeof和CHAR_BIT不准确的还是我误解了一些根本的东西? 
  long可能是一个64位的types,但是1仍然是一个int 。 您需要使用L后缀使1 long int : 
 unsigned long x = 1UL << 32; 
  (你也应该使用U后缀来使它unsigned ,正如我已经显示的那样,以避免左移一个有符号整数的问题。当一个long是64位宽,并且你移位了32位时,没有问题,但是它会是问题,如果你转移了63位) 
  unsigned long是32位或64位,这取决于您的系统。  unsigned long long总是64位。 你应该这样做,如下所示: 
 unsigned long long x = 1ULL << 32 
无符号长x = 1UL << 31;
不显示错误信息。 因为在你指定32之前,因为只限于0-31而不是真的。
你不能将一个值转移到最大位
 int x; // let int be 4 bytes so max bits : 32 x <<= 32; 
所以,这会产生警告
 left shift count >= width of type (ie type = int = 32 ) 
你可以用这样的东西:
 unsigned long x = 1; x = x << 32;