MKGAURAB's blog

By MKGAURAB, 10 years ago, In English

As mike told me to post this in a blog, I am posting.

I am confused about the compiler in CF. 8586981 submission get AC in GNU C++0x but same code gets WA 8586869 in GNU C++. Will you please enlighten me about this.

Thank you.

  • Vote: I like it
  • +9
  • Vote: I do not like it

»
10 years ago, # |
Rev. 3   Vote: I like it +12 Vote: I do not like it

I tested the program and get following results:

g++-4.8 -m64 test.cpp -O2 get right result.

g++-4.8 -m32 test.cpp -O2 get wrong result.

g++-4.8 -m32 test.cpp -O2 -std=c++11 get right result.

It's not a bug. It's just because, the constructor of bitset is defined differently in typical C++ and C++11. Reference of constructor of bitset is here.In typical C++, it's defined

bitset::bitset (unsigned long val);

Unfortunately, long is defined 32-bit on x86. So if you pass a long long to the constructor, it will be convert to 32-bit and all things will be wrong.

In C++11, it's defined

constexpr bitset::bitset (unsigned long long val) noexcept;

So everything will be right!

I didn't know this until I tested your program. Fortunately I never use bitset or I should have got some Wrong Answer because of this too.

Thanks for your good example which shows the difference between two standards to us.

Sorry for my bad English.