Tested r149624, 4.4.0 and 4.3.3 # ./gcc -v Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: ../configure --enable-languages=c,c++ --prefix=/mnt/svn/gcc-trunk/build/ Thread model: posix gcc version 4.5.0 20090714 (experimental) (GCC)
4.4.0 and 4.5 have better behaviour in the case of "switch" The following code: ------------------------------- unsigned f1(unsigned i) { switch (i) { case 0: return 0; case 1: return 1; case 2: return 2; case 3: return 3; default: return 4; } } unsigned f2(unsigned i) { if (i == 0) return 0; if (i == 1) return 1; if (i == 2) return 2; if (i == 3) return 3; return 4; } unsigned f3(unsigned i) { return i < 4 ? i : 4; } ------------------------------- f1(), f2() and f3() do the same, but the resulting code differs a lot. -- Summary: simple switch/case, if/else and arithmetics result in different code Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: zsojka at seznam dot cz GCC host triplet: x86_64-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40748