有关C ++位操作溢出的问题

时间:2018-09-22 05:30:39

标签: c++ bit

UPDATE tb_chapters AS t3 
JOIN 
(
SELECT t1.bid, IFNULL(COUNT(t2.id), 0) AS c
FROM tb_chapters AS t1 
LEFT JOIN tb_chapters AS t2 ON t2.bid = t1.bid 
                                AND t2.id < t1.id 
GROUP BY t1.bid 
) AS t4 ON t4.bid = t3.bid 

SET t3.order_id = t4.c 

结果是

#include <bits/stdc++.h>
int main() {
  uint64_t len = 10, x = 64;
  std::cout << (((1ULL << len) - 1) << x) << ' ' <<  (((1ULL << 10) - 1) << 64);
  return 0;
}

但是如果我编译代码“ -O2” 结果将是

1023 0

我的编译器:g ++(Ubuntu 7.3.0-16ubuntu3)7.3.0

为什么?

0 个答案:

没有答案