Fra*_*ank 3 c++ bit-manipulation
以下代码触发gcc警告(gcc 4.2.1):
#include <boost/cstdint.hpp>
boost::uint64_t x = 1 << 32; // warning: left shift count >= width of type
Run Code Online (Sandbox Code Playgroud)
不应该没问题,因为该类型有64位?
Rob*_*obᵩ 11
如何移位> = 32位
uint64_t?
如果您的编译器支持long long:
boost::uint64_t x = 1LL << 32;
Run Code Online (Sandbox Code Playgroud)
除此以外:
boost::uint64_t x = boost::uint64_t(1) << 32;
Run Code Online (Sandbox Code Playgroud)
不应该没问题,因为该类型有64位?
不.虽然x是64位,但1不是.1是32位.如何使用结果不会影响结果的生成方式.
| 归档时间: |
|
| 查看次数: |
3077 次 |
| 最近记录: |