Quote:Original post by Ned_K
I don't want a battle on which language is better, C or C++. Rather, are there certain things that C does more effectively than C++? I am already aware of the advantages of C++ with object oriented programming and the like, though I am currently only programming in C for classes and my own practice.
I spent years programming in C, and years programming in C++.
It is my opinion that C++ is an order of magnitude "better" than C, because it allows me to not have to worry about a lot of low level stuff with any runtime cost. That said, I've got decades of experience with both languages and have learned how to avoid most of the costlier hazards of C++ (though I continue to make the same hazardous errors in C).
C++ will do anything C will do, since it's a superset (yes, C99 added restricted pointers to do what a C++ compiler will already do with references, and it added "overloads" of math functions already in C++, but that was to catch up with C++). C++ can also produce faster code than C in many circumstances (eg. qsort() vs. std::sort()).
C++ was designed with the idea in mind (unlike competing languages like Java and C#) that if you don't use a feature, you shouldn't pay for it. Generally speaking, the cost of using a feature is the same as the cost of doing it yourself in C. For example, the cost of using a virtual function in C++ is the same, or cheaper, than the cost of a function lookup table and explicit indirection in C. The cost of passing an implicit "this" pointer in C++ is the same as explicitly passing a pointer to a data object in C. The list goes on.
Some will argue that they can accomplish the same thing in C as a C++ programmer could in that language, but on closer examination I find they have always meant they can accomplish less, but do it quicker. For example, it's faster to ignore return status values and not have error handling than it is to throw an exception. They are comparing apples and oranges.
The is no doubt C wins hands down when it comes to distributing software, since most major platforms ship with the C runtime. If they ship with the C++ runtime, it may not be the one for the compiler, or version of the compiler, that your program was compiled with. Runtime loadable modules run into the same problem: they may not be compatible with the program they are loaded or dynamically linked to. You end up either statically linking the runtime (huge executables), shipping your own copy of the dynamically-loaded runtime (effectively the same as static linking), or in the case of DSOs, wrapping everything in an 'extern C' interface.
So, in short there is nothing you can do in C that you can't do as well or better in C++, except distrubte software in a hassle-free way.