I'm converting some 32-bit compatible code into 64-bit - and I've hit a snag. I'm compiling a VS2008 x64 project, and I receive this warning:
warning C4334: '<<' : result of 32-bit shift implicitly converted to 64 bits
(was 64-bit shift intended?)
Here's the original line of code:
if ((j & (1 << k)) != 0) {
And here's what it looks like if I follow Microsoft's advice:
if ((j & (1i64 << k)) != 0) {
Is this safe to do, when the code will be compiled on both 32-bit and 64-bit systems? If so, please explain why I must add "i64" to the end, and why this will not affect a 32-bit compilation. Otherwise, a work-around would be much appreciated.
Beyond this, I have what looks like an even trickier bit of code.
if (id[j] != id[j ^ (1u << k)]) {
I understand that the "u" means that the digit is unsigned, but what's the point in specifying that on a value that doesn't exceed the signed maximum value... I'm guessing this has something to do with the bit shift?
1tostatic_cast<size_t>(1): 1) this removes the warning. 2) the continues to behave in exactly the same way as it did before and as expected (at least on MSVC 32bit and 64bit). 3) the code behaves as it should. 4) it's cross-plattform C++