How to offset> = 32 bits in uint64_t?
The following code triggers a warning gcc
(gcc 4.2.1):
#include <boost/cstdint.hpp>
boost::uint64_t x = 1 << 32; // warning: left shift count >= width of type
Shouldn't this be accurate since the type is 64 bits?
+3
Frank
source
to share
1 answer
How to shift> = 32 bits in
uint64_t
?
If your compiler supports long long
:
boost::uint64_t x = 1LL << 32;
Otherwise:
boost::uint64_t x = boost::uint64_t(1) << 32;
Shouldn't this be accurate since the type is 64 bits?
Not. Even if it x
's 64 bits, 1
no. 1
- 32 bits. How you use the result does not affect how the result is created.
+10
Robα΅©
source
to share