C vs. C++ vs. ...
Posted Jul 1, 2012 15:43 UTC (Sun) by
nix (subscriber, #2304)
In reply to:
C vs. C++ vs. ... by daniel
Parent article:
Why learn C? (O'Reilly Radar)
If you write the same program in C and C++ and compile it with GCC you will get the same object code because they use the same code generator and optimizer.
That's wrong: some transformations are done at the language-dependent tree stage, and these can differ between C and C++. Further, the languages have distinct constraints on the optimizer. e.g.:
Even exceptions these days are compiled so that exception handling generates code only on the throw path
That's wrong: C++ code that doesn't
use exceptions can still have them thrown through it at any points not marked nothrow (or marked as extern "C" or something similar to indicate the impossibility of exceptions emanating from those points), so not only are cleanup regions required, but a large number of additional abnormal edges are introduced which can and do constrain the optimizer. Thus, you'd often get different code compiling C code as C versus compiling it as C++, even if the optimizers and code generators were completely identical.
(
Log in to post comments)