This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Bit shift compiler bug or a corner case?
- From: Rohit Garg <rpg dot 314 at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 24 Nov 2011 01:25:08 -0500
- Subject: Bit shift compiler bug or a corner case?
Hi,
The following code outputs 0,1,32,33. Which is counter intuitive to
say the least. But if I replace the literal 1 with the type annonated
constant "ONE", the loop runs fine and outputs 0 and 1, which is what
I would expect.
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;
}
Any help will be greatly appreciated.
Thanks and Regards,
--
Rohit Garg
http://rpg-314.blogspot.com/
Graduate Student
Applied and Engineering Physics
Cornell University