The following code outputs are 0,1,32,33. Which, on the contrary, is intuitive. But if I replaced the literal 1 with the type of the annotated constant "ONE", the loop works fine.
This is with gcc 4.6.2 and -std = C ++ 0x.
#include<iostream>
#include<cstdint>
using namespace std;
int main()
{
int64_t bitmask = 3;
int64_t k;
const int64_t ONE = 1;
cout<<"bitmask = "<<bitmask<<endl;
for(k=0; k<64; k++)
{
if(bitmask & (1<<k))
{
cout<<"k="<<k<<endl;
}
}
return 0;
}
EDIT
Question: As Ben noted, 1 is considered to be 32-bit by default. Why it does not advance to 64 bits when its shared operand is 64 bits.
Decision
No. & L; <does not require each side to be of the same type. After all, why do the right side of int64_t when the maximum shift is available in char? Advancement occurs only when you are dealing with arithmetic operators, and not with all operators.
Copied from Bill's comments below.