r/cpp • • Jul 29 '19

Is auto-conversion of C++ code to a simpler, modern, and not backwards-compatible version possible?

I know that this kind of speculation doesn't go well here but could an automatic conversion of C/C++ code to a new language that's pretty close to modern C++ but with fixes (e.g. initialization syntax) and the bad parts removed (e.g. implicit conversions) ever be possible? A conversion to Rust or D would be harder. If it's possible, we could have a language with lesser cognitive load, able to use most legacy libraries and with the good and familiar features of C++ left intact. The performance might be somewhat worse - e.g. because memory initialization after allocations is desired. However, such a language wouldn't require as much work as completely new languages because it could just copy new features from C++.

53 Upvotes

122 comments sorted by

View all comments

Show parent comments

4

u/SkoomaDentist Antimodern C++, Embedded, Audio Jul 29 '19

In my experience the compiler tends to optimise away accidental doubles like in your example

Consider the case of simple float f2 = 1.3 * f1; The compiler cannot optimize that since 1.3f * f1 may differ from 1.3 * f1 (1.3 is not exactly representable in either float or double):

1

u/parkotron Jul 30 '19 edited Jul 30 '19

Well that's just what you get for using such ugly, inconvenient numbers. Stick to nice, clean, reliable sums of powers of two and it's a nonissue. ;)

Point taken.