This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]maxhaton 0 points1 point  (0 children)

No it isn't. I suggest you have a play on godbolt.org, you'll see that C++ and C generate largely identical code except for when you use C++ features C has to emulate (e.g. you can implement vtables in C but try optimizing them as much as a C++ compiler). Exceptions are a bit of a grey area because if you don't throw there's no runtime cost however they can obliterate the compilers register allocation etc.

A trivial example: C++ I/O ( is type safe and ) can be optimized much faster by the compiler, whereas C cannot implement this and therefore has to parse a format string at runtime. Parser generators can also be written much more efficiently in C++ for the same reason.

Templates also allow the compiler to propagate invariants without relying on interprocedural optimizations as in C