In the code: #include <iostream> typedef unsigned int uint; typedef long long int ll; int main() { int i = 0; ll a = uint(1); ll b = (uint(1) << (32 - i)); ll c = ((uint(1) << (32 - i)) - 1 ); ll d = (((uint(1) << (32 - i)) - 1) << 0); std::cerr << std::hex <<a << ":" << b << ":" << c << ":" << d << "\n"; }
the compiler: ~/ootbc/common$ g++ -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: ../gcc-4.0.2/configure --prefix=/home/ivan/gcc --enable-languages=c,c++ Thread model: posix gcc version 4.0.2 gives you: ~/ootbc/common$ a.out 1:1:0:0 whereas the correct result would be "1:0:ffffffff:ffffffff". Interestingly, on Cygwin the compiler: Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs Configured with: /gcc/gcc-3.4.4/gcc-3.4.4-1/configure --verbose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,ada,c++,d,f77,java,objc --enable-nls --without-included-gettext --enable-version-specific-runtime-libs --without-x --enable-libgcj --disable-java-awt --with-system-zlib --enable-interpreter --disable-libgcj-debug --enable-threads=posix --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptions --enable-hash-synchronization --enable-libstdcxx-debug : (reconfigured) Thread model: posix gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125) gives you: ~/ootbc/common: a.exe 1:1:0:7fffffff Ivan -- Summary: Bad code in unsigned shifts Product: gcc Version: 4.0.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: igodard at pacbell dot net http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26292