C vs C++
From WikiVS, the open comparison website
Contents |
[edit] Clearing misconceptions
- C++ is not just C with object orientation.
[edit] Performance
Both C and C++ compile code to the native CPU code. Because C is more low-level, it generally compiles in to faster and more optimized machine code.
C++ does not necessarily introduce any overhead that could be easily avoided in C trying to code the same functionality.
[edit] Available Libraries
Many libraries have APIs for both C and C++. Usually, one of them is a wrapper for the other, most often the C++ API being a wrapper around the C API.
| Library | C | C++ |
|---|---|---|
| Gtk+ | Yes | Wrapper as GTKmm |
| Qt | Bindings as Qt-C | Yes |
[edit] Software Implementations
Some projects use both C and C++ in their code. Because C is older and more polished, it is implemented more in critical applications and system components. Although C was the first choice in game programming some time ago, C++, in large part, has now taken over the commercial game industry.
| Software | C or C++ |
|---|---|
| Linux Kernel | C |
| Xorg | C |
| Windows | both |
| Compiz | C |
| Firefox | C++ |
| MySQL | C++ |
| PostgreSQL | C |
Programming language interpreters and compilers on von Neumann architecture systems are typically implemented using C, including C++ compilers.
[edit] Features
Because C++ is a language newer than C, and designed to be an improvement on C, it contains more features than C does, while maintaining most of the original C functionality. Features in C++ that are not in C include:
- Templates
- Streams
- Object Oriented Programming
- Overriding Operators
- Reference Passing
Features in C that C++ does not include:
- Fewer features. Many C advocates hold the opinion that C++ suffers an overabundance of "dangerous" features.
[edit] Learning curves and gotchas
In C++, the challenge is to learn how to use the libraries with efficiency. In C, you have to have a bit more knowledge on how things work at the lower level. As an example, in C, you have to know how pointers work to do advanced operations. In C++, pointers have been replaced with lighter methods. Pointers are among the most difficult concepts for a beginner to grasp.
Use of raw pointers in C tends to be much more straightforward than in C++, however. C++ is typically used when a developer wishes to have access to standardized object oriented programming abstractions, but incautiously mixing such abstractions with use of pointers to allocated memory can more easily result in memory leaks and segmentation violations.
In C++ the reliance upon destructors to release resources can also result in memory creep. As in many object-oriented languages, the possibility of circular references (where two objects maintain a reference to each other) can cause the objects to never be released from memory.
BlogMarks
del.icio.us
digg
Furl
reddit
Segnalo
Simpy
Slashdot
Spurl