C and C++ are iconic languages in which a huge amount of code is written. What path have they traveled to become ones? This article covers the emergence of C and the beginning of its official standardization. Also, you'll learn about C with Classes and its eventual transformation into C++.
1969. Apollo 11 visits the Moon. AT&T Bell Labs develops a language we all know today as C. At this time, a Unix operating system is at the early development stage.
In fact, the C language took over the main features from the B language. As well as the origin of its name. As for Unix, it was initially implemented in assembly language and didn't even have a compiler for high-level languages. This project's development attributes to one of the reasons for the C language creation.
In 1971, the compiler and some utilities in C were included in the second version of Unix. And in 1973, the Unix kernel was largely written in C.
Dennis Ritchie and Brian Kernighan published the first edition of the "The C Programming Language" on February 22, 1978. This book was the first widely available material on the C language.
Figure N1 - Cover of the first edition of the book "C Programming Language"
It has become a standard for C development from the time of its publication until the first official language certification. The "standard" was called K&R—after the first letters of the authors' last names.
This book introduced the "Hello World" program as an example of a minimal working program. After 1978, almost every book on programming languages couldn't do without this code example. Today, displaying "Hello World" as your first program is a well-established tradition.
#include <stdio.h>
main()
{
printf("Hello, World\n");
}
K&R presented several language features. For example, structures—a set of several variables grouped under a single name for ease of reference, as well as long int and unsigned int data types.
Addition/subtraction operators with assignment also changed in K&R C. Previously, to increase a value by one, you had to write a =+ 1, but such operators were confusing the C compiler. Besides, the difference between a =+ 1 (increase by one) and a = +1 (assignment) looked rather fragile from the human point of view. It was in K&R C that these operators turned into familiar ones—a += 1.
The code examples in the book were designed in a uniform style, which was also named after the first letters of the creators' last names. The K&R style is notable for the use of eight whitespaces as the main indentation (although four whitespaces are more commonly used). It is also called the "kernel style", as the Unix kernel is written in this style.
int foo(int is_bar)
{
if (is_bar) {
bar();
return 1;
} else {
return 0;
}
}
In May 1979, Bell Labs employee Bjarne Stroustrup began developing a system that was to be the first Unix cluster. In other words, he started to create a distributed computing system connected to a common network of several computers.
The problem was the lack of a suitable toolkit for this. Among the existing programming languages, there were two options that could help solve this problem, but both had nuances. The BCPL language was fast but unsuitable for large projects as it was quite close to low-level languages. The object-oriented programming language Simula, on the other hand, was suitable for the task but was quite slow. So Stroustrup set out to implement his own C-based language.
As early as October 1979, the CPRE preprocessor, adding classes, to C was ready. The language was called C with Classes. One could write the program code and pass it to the preprocessor. However, it was still considered to be an extension to C.
In addition to classes, the first version of C with Classes included:
The language was growing in popularity:
But even with that popularity, C only had the unspoken standard of K&R. Developers of the compilers were introducing a lot of non-standard changes to the language. This is when the problem of code portability began to heat up. The first C standard began to emerge given this range of issues.
In 1983, the American National Standards Institute (ANSI) formed a committee to draft the specification. The standardization process ended only in 1989, when the first standard for the language was ratified as "ANSI X3.159-1989: Programming Language C". In the same year, the second edition of the book "The C Programming Language" was published, describing the language as it appears in the standard. In a year's time, this standard was approved by the International Organization for Standardization (ISO) with minor changes.
Figure N2 - Cover of the second edition of the book "C Programming Language"
In addition to a setback of changes to the language since K&R, the standard included entirely new features, such as function prototypes and a more sophisticated preprocessor. The standard also included a description of the standard library composition. In addition, some means that hadn't been defined earlier were given more precise definitions.
In 1982, Bjarne Stroustrup began working on changes that would bring C with Classes out of the state, which its creator called a "medium success". Starting from that moment, it took a year to develop a compiler. Cfront came out in 1983.
Its key feature was that it converted C with classes into C code. After that, the converted code was passed to the C compiler. This feature enabled more people to use the compiler, as well as to use it on an existing Unix infrastructure.
As the language evolved, its name changed several times. It was first called C84 because the community called it just C. However, the name was also misleading, as it was more like a new C standard than a subset of the language. And it didn't actually help with the problem of the previous name. Eventually the language became known as C++, that is, C and the increment operator.
When moving from C with classes to C++, other new features appeared in the language:
The commenting style, which is still used today, took root at this very stage of language development. The style is used in other languages as well.
This is how C++ lived before the official certification. Stroustrup was rather promptly responding to the programmer community's requests. His was publishing works representing the standard descriptions of the language. So, the language was maintained mainly due to the efforts of its creator.
In February 1985, the first distributable version of C++ was released. In October of the same year, the language creator Bjarne Stroustrup released the first edition of the book "The C++ Programming Language."
Figure N3 - Cover of the first edition of the book "The C++ Programming Language"
It became the first tacit standard for the C++ language just like Kernighan and Ritchey's book "The C Programming Language." It was until the first official standard.
In the book, Stroustrup covered the language features as well as design issues from the C++ perspective, spicing up each point with plenty of code examples.
Since then, the book has been reprinted three more times, each time with language updates. At the time of writing, the most recent 4th edition includes the C++11 standard.
In July 1989, the Cfront 2.0 compiler was released. It was substantially revised compared to the previous version and also brought novelties to the C++ language.
At this time, templates have already become the talk of the town. No one doubted that they would be implemented, as it was a realistic objective. As for another potential outstanding feature—multiple inheritance—was a real challenge for the creators from the programming community. Many have said that implementing multiple inheritance in C++ is impossible. In Simula, for example, a similar suggestion was rejected because of the inevitable complexity of the garbage collector. However, multiple inheritance was badly needed, as it would greatly simplify the development of libraries whose code was quite cumbersome without it.
As a result, multiple inheritance was added in Cfront 2.0 after all. This addition to the language has sparked controversy. For example, some have argued that the Smalltalk language, the epitome of object-oriented programming, doesn't have multiple inheritance. That's why C++ certainly shouldn't adopt it. The language creator assumed that such a reaction is due to taking multiple inheritance too seriously.
The above C++ version also introduced:
In 1990, Borland released the Borland C++ integrated development environment for developing C and C++ programs (what a twist, hah?). It was originally intended for development under DOS, but later Windows support was introduced as well.
Figure N4 - Screenshot from Borland C++
Historically, Borland C++ was a descendant of Turbo C but incorporated the hallmarks of C++—support of object-oriented programming.
Each version of the environment had its own compiler supporting its own standards. Over time, Borland C++ got a lot of specialized libraries for fast application development.
The last Borland C++ IDE version was released in 1997, after which it was replaced by the Borland C++ Builder series. The finale of Borland C++ came in 2000 with the release of Borland C++ 5.5 coming with a compiler.
Borland C++ was a nice cozy editor for DOS. There was even some kind of syntax coloring.
Yuri Minaev, the architect of C and C++ core of PVS-Studio analyzer
Four years after Borland, Microsoft released its Visual C++ integrated development environment.
In 1986, Bjarne Stroustrup wrote an article "What is Object-Oriented Programming?" in which he voiced three flaws of C++:
Multiple inheritance was introduced in 1989 with C++ 2.0, and the rest of the flaws were fixed in 1990 with new language features. They were described by Stroustrup in the book "Annotated C++ Reference Manual".
Templates and exception handling appeared soon, one after another. Templates were approved in Seattle in July, and the exception handling mechanism was approved in Palo Alto in November. Their close releases are due to the fact that both of these innovations address similar problems. According to the language creator himself, templates allow you to reduce the number of errors during program execution by extending the capabilities of the static type system. While exceptions allow you to handle the remaining errors.
Parameterized types were considered back in the first edition of C++. Yet they had to be postponed due to a lack of time for sufficient study of design and implementation issues. Exceptions were also postponed for the same reason. And it wasn't for nothing. Their design lasted from 1984 to 1989.
The "Annotated C++ Reference Manual" also introduced namespaces and the ability to identify types at runtime.
Generic programming started to gain momentum at that point. C++ with templates was not a pioneer. When creating templates, the creators were drawing ideas from ML, CLU, and Ada programming languages.
However, it is safe to say that C++ was promoting this paradigm. Templates made it possible to write code without macros in many cases, reducing the chances of shooting oneself in the foot. Here comes a fly in the ointment —the fully operating functionality that simplifies work with generic programming appeared only by C++20. But even that didn't stop programmers when they learned that templates could enable computations at the compilation stage...
On the other hand, exceptions in C++ are not that clear-cut. Unfortunately, they did not solve all the error handling problems compared to earlier approaches. The control flow becomes non-trivial when using exceptions. There are tons of ways to shoot oneself in the foot with them, such as privately inheriting exceptions, catching exceptions by value, or arranging catch blocks in the wrong order, etc. As a result, some coding standards prohibit their use, such as Google C++ Code Style.
Philipp Khandelyants, Team Lead of the C and C++ development team at PVS-Studio
"Annotated C++ Reference Manual" has become some kind a precursor to the official C++ standardization. It described all the innovations that would soon become the standard for the language.
In this article, we covered events in the history of C and C++ from 1969 to 1990. In the next article, we will delve into the history of C++ from 1991 to the present day: