(no title)
dianeb | 7 years ago
That aside, the comparison of programming languages to automobiles still holds: C is a Formula One race car without seatbelts. C++ now resembles Ada in terms of size to the extent that it's a large staff car that comes in only one color. Java, which originally seemed to be a sane C++, is sort of like my father's Buick -- it looks nice but when you really need to do something slightly out of the ordinary like carry skis you can't do it without an accessory. That's right, it is a proprietary language (hence C#)
kazinator|7 years ago
C++ contains a subset which is a dialect of C that is so compatible with C (in particular C90) that you can write code in it that compiles as C, and with very little effort. (Which I know from extensive personal experience, not just theory).
(Such code benefits from the extra checks and diagnostics C++ provide; and with some #ifdef switching and macros, it can take advantage of some additional C++ diagnostic fatures when being compiled as C++.)
Quotes from Bjarne Stroustrup's C++ FAQ:
"Well written C tends to be legal C++ also."
"It is not uncommon to be able to convert tens of thousands of lines of ANSI C to C-style C++ in a few hours. "
kazinator|7 years ago
C++ does add some unsafe features that don't exist in C.
In C++, it is possible to convert a
to a without a cast, and without a diagnostic, where foo and bar are different struct types. C doesn't permit this.Specifically, C++ allows this in the situation when foo is derived from bar by inheritance, a relationship that doesn't exist in C.
Subsequently, pointer arithmetic is allowed on the converted pointer. the bar pointer can be displaced by 1. But the underlying array is of foo objects; it's the wrong size.