To choose between C and C++, rate them on the comparison parameters by entering scores (+ve or -ve) in the comparison tool.
The total points are automatically shown in the top row. This should help you decide.
Dennis Ritchie of the Bell Labs designed the C, a general purpose computer programming language in 1972 for use with UNIX, an operating system of then. C is predominantly used for system software programming, but is also very useful for creating general application software. Some of the adjectives used to describe C are block structured, imperative & procedural language.
C++(originally named "C with Classes" and still known as the superstructure of C in computer circles) was developed as an enhancement of C by Bjarne Stroustrup in 1983 at the Bell Labs. Stroustrup, in 1979, started by adding classes, virtual functions, operator overloading, multiple inheritance, templates, exception handling etc. The C++ programming language standard was ratified as ISO/IEC 14882:1998 in 1998 and the current version is the 2003 version, ISO/IEC 14882:2003 which is infact the corrected version of the C++ 1998. The "Library Technical Report 1", released in 2005 gives details of extensions to the standard library without being a part of the standar version. A new version of the standard (informally known as C++0x) is under development. C++ has been a highly successful commercial programming language since 1990. Though C++ is royalty-free, its documentation is not freely available.
C proved very useful in running applications coded in assembly language because of its strengths like a simple compiler, lower access levels of memory, lower run time support and an efficient constructing language that was in sync with the hardware instructions. Another of its credits is that it is a highly portable (compatible with a variety of OS & Platforms) with very minimal source code changes required. Thus it has enabled remote operations & independence from the hardware. C is also compliant to a variety of standards, making it work with everything.
C++ is known as a mid-level language. Due to the fact that the C++ comprises of both high-level and low-level language features. Some of the adjectives used to describe C++ are static typed, free-form, multi-paradigm and supporting procedural programming.
Stroustrup, while programming for his Ph.D thesis, found that the Simula language had high level features helpful for large software development, but was too slow for practical use, while the BCPL (language) was fast, but too low-level and thus unsuitable for large software development. In Bell labs, he had to analyze the UNIX kernel with respect to distributed computing which created further problems and he set out to enhance C (due to its ultra portable nature) with features from the Simula. C++ was created in 1983 with additional features like virtual functions, function name and operator overloading, references, constants, user-controlled free-store memory, improved type checking and single-line comments with two forward slashes (//). The Cfront (commercial version) was released in 1985 with the class, derived class, strong type checking, inlining, and default argument features. 1985 also saw the release of the The C++ Programming Language, an important reference to the language in the absence of an official standard. This was followed by the release of the C++ 2.0 in 1989 with features like multiple inheritance, abstract classes, static member functions, const member functions and protected members. Features like templates, exceptions, namespaces, new casts and Boolean type were added post 1990.
Along with the language, its library also evolved, with several additions like the stream I/O library, the Standard Template Library etc.
The first editions of the book K & R written by Dennis Ritchie & Brian Kernighan (original name: The C Programming Language) describes their version of C as the K & R C with full specifications, while the later editions include the ANSI (American National Standards Institute) C standards. Some of the salient features described are the introduction of various data types, removal of several semantic ambiguities, omission of other function declarations etc. Even after the introduction of the ANSI C, the K & R C continued to be the most portable programming language for programmers due to its wider compatibilities.
K&R function declarations did not include any information about function arguments leading to non-performance of function parameter type checks, although some compilers issued a warning message if a local function was called with the wrong number of arguments or if multiple calls to an external function used different numbers of arguments. Tools such as UNIX's lint utility were created for checking the consistency of functions used across multiple source files.
Some of the important characteristics of C are as follows:
Structured programming facilities
Confirming to the ALGOL traditions
Short circuit evaluation – usage of only one operand if the result can be determined with it alone
Static typing system for avoiding unintended operations
Value passed parameters with relevance to pointer value passing
Heterogeneous data combination & manipulation
Reserved keywords and free-format source text
Larger number of compound operators, such as +=, ++
Huge variable hiding capacity, though function definitions being non-nestable
Character – integer usage similar to assembly language
Low-level access to computer memory via machine addresses and typed pointers
Function pointers allow rudimentary forms of closures & polymorphic runtime
Pointer arithmetic defined Array indexing (secondary notion)
Standardized processor for defining macros, including source code files & conditional compilations
Complex Input/Output and mathematical functions with consistent delegation to library routines
Syntax same as “B” (C’s predecessor) but different from ALGOL e.g.: { ... } replaced begin ... end, && and || replaced and & or, which
While B used & and | in both meanings, C made them syntactically distinct from the bit-wise operators
Similarities to Fortran e.g: the equal- sign for assignment (copying) & two consecutive equal-signs to test for equality (compare to EQ) or the equal-sign in BASIC)
Other unofficial features added with time were:
void functions
Functions returning struct or union types instead of pointers
Assignments enabled for struct data types
const qualifier to make an object read-only
Enumerated types
Creationg of tool to avoid the inherent problems of the language
Soon C became powerful enough to have the UNIX Kernel (written in a assembly language) re-written making it one of the first OS Kernels written in a language apart from the assembly languages.
C++ is designed to be a statically typed, general-purpose language that is as efficient and portable as C
C++ is designed to directly and comprehensively support multiple programming styles (procedural programming, data abstraction, object-oriented programming, and generic programming)
C++ is designed to give the programmer choice, even if this makes it possible for the programmer to choose incorrectly
C++ is designed to be as compatible with C as possible, therefore providing a smooth transition from C
C++ avoids features that are platform specific or not general purpose
C++ does not incur overhead for features that are not used
C++ is designed to function without a sophisticated programming environment
Polymorphism, one of the prominent qualities of C++, enablesmany implementations with a single interphase and for objects to act according to circumstances. C++ supports both static (compile-time) and dynamic (run-time) polymorphisms. Compile-time polymorphism does not allow for certain run-time decisions, while run-time polymorphism typically incurs a performance penalty. C++, though considered a superset of C, there exist a few differences causing some valid C codes to be invalid in C++ or to behave differently in C++. Issues like the C++ defining new keywords namely new & class, that are used as identifiers in C. C and C++ codes can be intermixed by declaring any C code that is to be called from/used in C++ with C linkage & by placing it within an extern "C" { /* C code */ } block.
With time, standardization became more and more important because of large numbers of extensions and a random library with growing popularity of the language and the lack of precise implementation of compilers as per the specifications. One of the aims of the C standardization process was to produce a superset of K&R C, incorporating many of the unofficial features introduced subsequently. However, the standards committee included several new features like function prototypes, void pointers, support for international character sets and locales and a more capable preprocessor. The syntax for parameter declarations was also augmented. Post 1970s, C replaced BASIC as the leading language for microprocessor programming and became popular with its collaboration with the IBM PCs. Meanwhile, Bjarne Stroustrup and others at Bell Labs began work on creating the C++, which added object-oriented programming language constructs to C. Further, ANSI formed a committee in 1983 called X3J11, to establish a standard specification of C and in 1989, the standard was ratified as ANSI X3.159-1989 "Programming Language C." This is the version of C that is often referred to as ANSI C, Standard C or C89. C90, introduced in 1990, was ame as C89 barring a few minor changes. While C++ evolved rapidly, C remained static until 1995 when the Normative Amendment 1 created a new standard which underwent further revision, leading to the publication of ISO 9899:1999 in 1999. This standard is commonly referred to as "C99." It was adopted as an ANSI standard in March 2000. Some of the newer functions are mentioned below:
Inline functions
Ability to declare variables anywhere, instead of only after another declaration or at the start of a compound statement
New data types like long long int, optional extended integer types, explicit boolean data type and complex type to denote complex numbers
Array lengths can be variable
One-line comments beginning with // supported
Library functions like snprintf
New header files, such as stdbool.h and inttypes.h
Type-generic math functions (tgmath.h)
Improved support for IEEE floating point
Designated initializers
Compound literals
Support for variadic macros (macros of variable arity)
C++, while continuing to evolve to meet the requirements of the future, a newer version called C++0x denoting that it is expected to be released before 2010 is currently being developed. Indications suggest that C++ will continue to capitalize on its multi-paradigm nature and notable improvements may bee native support for threading and concepts thereby making working with templetes easier. More controversially, adding garbage collection is currently under heavy discussion. A group called Boost.org, that advises the C++ standards committee on good features and improvements required, is working extensively to develop C++ in its current form with expanded functional and metaprogramming abilities.
In The Design and Evolution of C++ (1994), Bjarne Stroustrup describes some rules that he used for designing the C++. Knowing the rules helps to understand why C++ is the way it is. Much more detail can be found in The Design and Evolution of C++.
C’s influence can be traced to works like awk, csh, C++, C#, D, Objective-C, Concurrent-C, BitC, Java, JavaScript, Limbo, Perl, PHP etc. Some of the major implementations of C include the Borland C, Watcom C, GCC & MSVC. C++, to its credit has influenced other works like D, C#, ADA 95, Aikido, Java & PHP.
Despite its popularity, C has been criticized for having desirable operations being too hard to achieve and undesirable operations being too easy to accidentally invoke thereby involving more programmer skill, experience, effort, and attention to detail than other programming languages for the safe & effective use of the language.
When object-oriented languages became popular, C++ was an extension of C that provided object-oriented capabilities with C++ originally implemented as a preprocessor -- source code was translated into C, and then compiled with a C compiler.
C++ being derived from C, also happens to inherit most of the criticisms leveled against C. But since the language is actually a composition of two different languages, along with the load of huge programs, often end up making the compilation huge and inappropriate in terms of pure size. When this problem is tried to be avoided, by disabling some of the fringe codes, it was again criticized for losing out on several important utilities. The creator of C++ also feels that C++ is justified to be a complex language since the modern day programming requirements have also increased in a huge manner when compared to the yesteryears.
A real-life project written in C and C++ may help to get the point.
TrustLeap G-WAN is a Web Server which is faster (in user-mode) than IIS 7.0 (in the kernel).
G-WAN ANSI C89 ('edit & play') scripts are 5x faster than ASP.Net C#.
G-WAN is up to 38x faster than Apache.
G-WAN is up to 25x faster than Nginx.
G-WAN was started in C++ and then converted to C because of the '++' overhead. The gain was not only in footprint (currently 106 KB), but also in performances (~180%).
If you want to know what makes C++ so bad, just try virtual inheritance and virtual functions, and then compare the machine code generated by the C++ compiler with a clean C implementation of the same features (the C++ code is twice larger -and slower).
Conclusion: if you are targeting performances then you can use C++ as long as you write C code compiled with a C++ compiler.
Linus is a programmer that make systems work, and Bjarne is a programmer that uses the systems created by programmers like