繁体   English   中英

如何在uint64_t中移位> = 32位?

[英]How to shift >= 32 bits in uint64_t?

以下代码触发gcc警告(gcc 4.2.1):

#include <boost/cstdint.hpp>
boost::uint64_t x = 1 << 32; // warning: left shift count >= width of type

不应该没问题,因为该类型有64位?

如何在uint64_t移位> = 32位?

如果您的编译器支持long long

boost::uint64_t x = 1LL << 32;

除此以外:

boost::uint64_t x = boost::uint64_t(1) << 32;

不应该没问题,因为该类型有64位?

不。即使x是64位, 1也不是。 1是32位。 如何使用结果不会影响结果的生成方式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM