This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bug in bitset


Try this:

#include <iostream>
#include <bitset>
using namespace std;

int main()
{
  bitset<70> bs;
  bs.set(0);
  bs <<= 32;
  for (int i = 69; i >= 0; --i)
    cout << bs[i];
  cout << '\n';
}

Result:
0000010000000000000000000000000000000100000000000000000000000000000000

I have gcc version 2.95.3, but I think there's the same bug in some later
versions.

In a "shift left" function in bitset, when they shift by x bits,
they do "<<=(x%32)" and ">>=(32-x%32)" for each word, the second is 
incorrect for x==32, because you can only shift by 0..31 bits.

Tomek



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]