C vs C++

From WikiVS, the open comparison website

Jump to: navigation, search


Contents

[edit] Clearing misconceptions

  • C++ is not just C with object orientation.

[edit] Performance

Most C and C++ implementations compile code to the native CPU code. Utilizing C++ features such as virtual methods can lead to more bloated applications than a more static, C style implementation. However, C++ was designed with a "no overhead rule", meaning that code will not suffer from overhead of features not used. Therefore it is possible to write code in a procedural style that will run as fast as the comparable C program.

[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.

Libraries Available in C and C++
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 in C/C++
Software C or C++
Linux Kernel C
Xorg C
Windows both
Compiz C
Firefox C++
MySQL both
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 language constructs not present in C, while maintaining most of the original C functionality. Some features from C++ were put into the C99 standard. Features in C++03 that are not in C99 include:

  • Templates
  • Streams
  • Inheritance
  • Class encapsulation
  • Virtual methods
  • Overloaded operators
  • Reference passing
  • Exceptions

Using some of these features, such as exception handling, can slow down programs.

[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++, alternatives, like references, have been introduced, as well as keeping pointers. 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.

[edit] Links

[edit] Pro C

[edit] Pro C++

Personal tools
Related Ads