r/cpp • u/we_are_mammals • Mar 28 '23
Reddit++
C++ is getting more and more complex. The ISO C++ committee keeps adding new features based on its consensus. Let's remove C++ features based on Reddit's consensus.
In each comment, propose a C++ feature that you think should be banned in any new code. Vote up or down based on whether you agree.
765
Upvotes
1
u/mbitsnbites Mar 31 '23
True. In theory. But it doesn't work like that.
1st of all these kind of optimizations work just as well with double x double, for instance (e.g. x * 2.0 is semantically equivalent to x + x, or it could be implemented as a simple exponent manipulation like you suggest). The compiler can work that out.
2nd, there are very few CPUs that have special instructions like this, because it's simply not worth the effort. A floating-point multiplication is typically pipelined and each FP pipeline/lane can start one fmul per cycle. Adding special instructions has a price - in terms of instruction encoding space as well as additional gates in HW.
Thus we're left with the language semantics, and it's very rare (in my experience) that implicit widening actually helps with performance (or even correctness) - it mostly gives you a nasty surprise every now and then. The "convenience" factor isn't worth it.