Why did history choose C language? Facts have proved that the C language in its twilight years is still not old!

Time:2021-9-4

The emergence of any new thing does not come from chance, but the inevitable result driven by the times.

 

1、 Development of C language

1. How great is the C language

If you ask me: how great is the C language. Well, I might think about it and say: I don’t know how great it is, but I know it’s great.

 

Here, I would like to say something that may be a little one-sided, that is: in today’s world, wherever there is electricity, there may be the shadow of her (C language) or her descendants.

Any language lower than C language is not enough to completely abstract a computer system; Any language higher than C can be implemented in C.

2. Father of C language

 

Dennis macalistair Ritchie (English: Dennis macalistair Ritchie, September 9, 1941 – October 12, 2011), American computer scientist. Hacker circles often call him “DMR”. He is the creator of C language and the key developer of UNIX operating system. He has had a far-reaching impact on the computer field, and is the winner of the Turing Award in 1983 together with Ken Thompson.

 

Timeline of Dennis rich’s life

Professor Martin of the computer department of MIT commented: “if jobs is the king of visual products, rich is the monarch of the Invisible Kingdom. Jobs’s contribution is that he understood the needs and desires of users so well that he created scientific and technological products that make contemporary people happy. However, it is Mr. rich who provides the core components for these products. People can’t see these components, but they are used every day“ Kenihan commented: Newton said he stood on the shoulders of giants. Now, we all stand on rich’s shoulders.

3. Ancestors of C language

For the sake of brevity, I (Dennis M. Ritchie) omitted the complete description of C itself, its parent B [Johnson 73] and its grandparents BCPL [Richards 79], and only focused on the characteristic elements of each language and how they evolved. This paper is about the development of the C programming language, the influences on it, and the conditions under which it was created. For the sake of brevity, I omit full descriptions of C itself, its parent B [Johnson 73] and its grandparent BCPL [Richards 79], and instead concentrate on characteristic elements of each language and how they evolved.

This passage comes from an article on the development history of C language written by Dennis M. Ritchie, the father of C language, which clearly points out that C language originates from B and BCPL. C language can be seen as standing on the shoulders of giants and conforming to the trend of the times.

1) Father of BCPL language

Martin Richards

Martin Richards (English: Martin Richards, July 21, 1940 -), born in Britain, is a computer scientist. He is the inventor of BCPL programming language and developed the Tripos operating system.

In 1966, Martin Richard invented BCPL programming language based on CPL programming language at Cambridge University.

2) Father of B language

Kenneth Lane Thompson

Kenneth Lane Thompson (English: Kenneth Lane Thompson, February 4, 1943 -) nickname Ken Thompson (English: Ken Thompson), American computer science scholar and engineer. Hacker culture circles usually call him “Ken”. During his work at Bell Labs, Thompson designed and implemented the UNIX operating system. He created B language (based on BCPL) – the predecessor of C language, and he is one of the creators and developers of Plan 9 operating system. He was also the winner of the 1983 Turing Award with Dennis Ritchie.

In 2006, Thompson joined Google and co designed the go language with others.

3) A set of photos of Ken and Dennis

Increasingly refined, standing on the shoulders of giants

Ken is sitting and Dennis is is standing

teach by precept and example

Thank Dennis rich for leaving the world a “C language Bible”

Unfortunately, the author studied the C language of Mr. Tan Haoqiang in college

Dennis and the C programming language

4. C language timeline

 

From the timeline in the figure, we can clearly see the origin of C language and time nodes.

Sometimes we have to say that the times created heroes. The famous operating system UNIX was born from Ken Thompson between 1969 and 1971. As a large-scale systematic software, it is extremely necessary to have a reliable high-level language (the low-level language at that time refers to assembly, because the previous operating system was written in assembly). At this time, Dennis rich was not idle. After improving the B language, he gave birth to the C language with types (according to rich himself, this improved language was called NB for some time). Namely: new B. However, in the eyes of those of us who eat melons, it is true (NB).

In 1971 I began to extend the B language by adding a character type and also rewrote its compiler to generate PDP-11 machine instructions instead of threaded code. Thus the transition from B to C was contemporaneous with the creation of a compiler capable of producing programs fast and small enough to compete with assembly language. I called the slightly-extended language NB, for `new B.’

5. UNIX timeline

 

The birth of UNIX is closely related to the wide spread and use of C language.

The timeline above only shows the first few UNIX versions born in the same time period as C language (of course, if you are interested, you can query the history of UNIX, which will definitely surprise you. Some of the most famous branches: BSD, MINIX, Linux…).

Next, trace the emergence of C language by finding some UNIX kernel source code on the Internet.

1) PDP-Unix

PDP UNIX system kernel code file

PDP-7 Unix 

 

You can see that they are basically written in assembly (file name suffix. S). Why use the word basic? Because some commands in the system are written in B language.

2)First Edition Unix

First edition UNIX system kernel code file

 

As you can see, it is still written in assembly (file name suffix. S).

3) Second Edition Unix

Second edition UNIX system kernel code file

 

Second Edition Unix The second edition of Unix was developed for the PDP-11 at Bell Labs by Ken Thompson, Dennis Ritchie and others. It extended the First Edition with more system calls and more commands. This edition also saw the beginning of the C language, which was used to write some of the commands.

By this version, you can already see the figure of C language.

4) UNIX and C language

Since the appearance of C language in UNIX V2 and the V3 version of UNIX, a large number of code written in C language can be seen in the UNIX kernel.

According to rich, by the beginning of 1973, the basic knowledge of modern C had been completed. The C language and compiler are powerful enough for us to rewrite the UNIX kernel of PDP-11 in C that summer (that is, the V3 version of Unix).

By early 1973, the essentials of modern C were complete. The language and compiler were strong enough to permit us to rewrite the Unix kernel for the PDP-11 in C during the summer of that year.

At this time node, it is basically certain that most of the cores of C language and UNIX have been improved. What remains to be done is portability and standardization.

You may have heard of the following story: later, UNIX was used in academic and government organizations. It was precisely because of the popularity and prosperity of UNIX that C language was widely spread and used.

In the 1980s, the use of C language spread widely, and almost all machine architectures and operating systems can use compilers. In particular, it has become a programming tool for personal computers. It is very popular not only for commercial software manufacturers for these machines, but also for end users interested in programming.

During the 1980s the use of the C language spread widely, and compilers became available on nearly every machine architecture and operating system; in particular it became popular as a programming tool for personal computers, both for manufacturers of commercial software for these machines, and for end-users interested in programming.

This is the so-called mutual achievement.

In a word, we are not afraid of gain and loss, improve day by day, and finally achieve each other.

6. How was the first c compiler written?

I don’t know if you have ever thought that everyone uses C language or language based on C language to write compilers, so how did the world’s first C language compiler be written? This is not a “chicken and egg” problem

Review the history of C language: tomphson developed B language on the basis of BCPL, and Ritchie successfully developed the current C language on the basis of B language. Before C was used as the system programming language, tomphson also wrote the operating system in B. It can be seen that before the implementation of C language, B language can be put into practice. Therefore, the prototype of the first C language compiler may be written in B language or a mixture of B language and PDP assembly language.

As we all know now, the execution efficiency of B language is relatively low, but if it is written in assembly language, it will not only have a long development cycle and difficult maintenance, but also lose the necessary portability of high-level programming language.

Therefore, the early C language compiler took a clever way: first write a subset of C language compiler in assembly language, and then recurse through this subset, so as to complete the complete C language compiler.

The detailed process is as follows: first create a subset with only the most basic functions of C language and record it as C0 language. C0 language is simple enough to directly write C0 compiler in assembly language. Relying on the existing functions of C0, another subset of C language C1, which is more complex than C0 but still incomplete, is designed. C0 belongs to C1 and C1 belongs to C. the compiler of C1 language is developed with C0. On the basis of C1, another subset of C language C2 language is designed. C2 language is more complex than C1, but it is still not a complete C language. The compiler of C2 language is developed… So until CN, CN is powerful enough, it is enough to develop the implementation of a complete C language compiler. As for the number of N here, it depends on the complexity of your target language (here is C language) and the programming ability of programmers. In short, if you can easily use the existing functions to implement C language at a subset stage, you will find n. The following figure illustrates this abstract process:

 

https://kknews.cc/tech/bx2r3j.html   This paper introduces the concept of “self compile”, that is, for some strong types with obvious bootstrap nature (the so-called strong type is that each variable in the program must declare a type before it can be used, such as C language, on the contrary, some scripting languages have no type at all), programming languages can use a limited subset of them, They express themselves through a limited number of recursions. Such languages include C, Pascal, ADA, etc. for why they can be self compiled, see the compilation principles of Tsinghua University Press, which implements a compiler for a subset of Pascal. https://zhuanlan.zhihu.com/p/136102461

This process also found evidence in the UNIX V2 version.

 

Ken Thompson, Dennis Ritchie and others developed the second version of UNIX for PDP-11 at Bell Labs. It extends the first edition with more system calls and more commands. This release also saw the beginning of the C language, which is used to write some commands.

The code here is only the source code of some commands, some library functions and C compiler. The files in C / are from last1120c.tar.gz tape and constitute an effective c compiler for UNIX version 2.

The second edition of Unix was developed for the PDP-11 at Bell Labs by Ken Thompson, Dennis Ritchie and others. It extended the First Edition with more system calls and more commands. This edition also saw the beginning of the C language, which was used to write some of the commands.The code here is only the source to some of the commands, some of the library functions, and the C compiler. The files in c/ come from the last1120c.tar.gz tape, and form a working C compiler for Second Edition Unix.

After downloading and decompressing the source code, the directory structure is as follows:

 

Interested partners can download it and study it.

2、 Comparison of BCPL, B and c languages

If you want to find a good way to compare programming languages, it’s code.

1. Three language code examples

The following uses BCPL, B and C to implement a simple program: the program adds the three numbers a, B and C, assigns the result to sum, and finally prints the sum.

1) BCPL language example

GET “libhdr”

LET start() = VALOF

{ LET a, b, c = 1, 2, ,3

sum := a + b + c

writen(sum)

}

Let declare variables;

: = the symbol is the assignment symbol, which also exists in go, indicating the internal local variable of the function. The interesting point here is that Ken Thompson, the father of B language, changed the = symbol to the = symbol. Now, as one of the fathers of go language, I invite the = symbol back (fate ~).

In the transition from BCPL to B, it is decided to use a single character = instead of assignment: = other fiddles in the transition from BCPL to B were introduced as a matter of taste, and some remain Continental, for example, the decision to use the single character = for assignment instead of: =. Similarly, B uses / * * / to enclose comments, where BCPL uses / /, to ignore text up to the end of the line. The legacy of PL/I is evident here. (C++ has resurrected the BCPL comment convention.) Fortran influenced the syntax of declarations: B declarations begin with a specifier like auto or static, followed by a list of names, and C not only followed this style but ornamented it by placing its type keywords at the start of declarations.

2) B language example

Language structure of B language

main() {

— statements —

}

newfunc(arg1, arg2) {

— statements —

}

fun3(arg) {

— more statements —

}

B language code example

main() {

auto a, b, c, sum;

a = 1; b = 2; c = 3;

sum = a+b+c;

putnumb(sum);

}

The statement Auto… Is a declaration. That is, it defines the local variables to be used within the function;

Putnum B is a library function with parameters, which will print a number on the terminal.

3) C language example

#include

void main(){

int a,b,c,sum;

a=1; b=2; c=3;

sum = a+b+c;

printf(“%d”, sum);

}

2. The difference between the three in the sample code

The difference between the three can be seen from the above example:

The writing method of C language is closer to that of B language;

BCPL and B languages are typeless languages, and word / cell is used to represent a fixed length bit. C language is typed.

There are some places you may be interested in:

++, — the symbol was invented by Thompson;

&&, | was introduced in C language.

explain:

After checking for a long time, I only found some code fragments of BCPL and B language. As for whether I can run, I don’t know ^ ^;

If you want to know the specific differences between the three, it is recommended to read Dennis rich’s article on the history of C language development;

BCPL and B languages have also experienced several version iterations (because there are many different ways to write code fragments found on the Internet). For example, the B code fragment found in Wikipedia is written differently from that found in previous versions of the UNIX kernel. Personal speculation is a version problem. Different versions have different writing methods);

C language is closer to B language, or many new features are added on the basis of B (two questions are thrown: 1. Why didn’t rich name B + + like C + +? 2. Why does C + + use two plus signs instead of one, called C +?   Students with big brain holes are welcome to comment;

If a master thinks there is a problem with the above code fragment or knows how to run, he can communicate privately.

3、 Why did history choose C language

In the late 1960s, Bell laboratory’s research on computer system entered a prosperous period. The mutlics project cooperated by MIT, general electric and Bell laboratory ended in failure (around 1969). It was during this period that Ken Tompson began to write alternatives to mutlics. He hoped to build a comfortable computing system (that is, Unix) according to his own design. Later, when writing the first version of UNIX, he felt that UNIX needed a new system programming language, and he created a B language. B language has no type of C. to be exact, B language is the language generated by Tompson after squeezing BCPL into 8K memory and being filtered by his personal brain.

Due to some problems in B language, it is only used to write some command tools. Just in this period, Ritchie redesigned and improved on the basis of B language, thus giving birth to C language.

In 1973, the C language was basically complete. From the language and compiler level, it was enough for Tompson and Ritchie to rewrite the UNIX kernel in C language. Later, UNIX gradually became popular in some research institutions, universities and government agencies, which led to the development of C language.

In 1978, the C programming language written by K & R was published, which further promoted the popularization of C language.

To sum up in one sentence: the right time, the right place, the right people and tools appear (the relationship between UNIX and C language is a bit like the relationship between GNU and Linux kernel, which are mutual achievements).

4、 Standard C library and code

After several iterations, C language and its standards have become what we see today. Many C standard libraries are specified in its standards, and different systems have their own different code implementations.

Of course, the Linux kernel also has code that implements the standard C library. Let’s enjoy her beauty.

1. Standard C library

ANSI C includes a total of 15 header files. In 1995, normal Addendum 1 (Na1) approved three header files (iso646. H, wchar. H and wctype. H) to be added to the C standard function library. C99 standard adds 6 header files (complex. H, fenv. H, inttypes. H, stdpool. H, stdint. H and tgmath. H). Five header files (stdalign. H, stdatomic. H, stdnoreturn. H, threads. H and uchar. H) have been added to C11 standard.

So far, the C standard function library has 29 header files:

 

2、 linux/lib/string.c

Linux kernel version: 4.18.13

The following three string processing functions are listed: strcpy(), strncpy(), and strncat(). The code was written by Linus Benedict Torvalds. Why? Look at the code header comments, or the familiar taste stupid. People who have seen git source code should also know that there are similar comments in Git source code.

// SPDX-License-Identifier: GPL-2.0

/*

*  linux/lib/string.c

*

*  Copyright (C) 1991, 1992  Linus Torvalds

*/

/*

* stupid library routines.. The optimized versions should generally be found

* as inline code in

*

* These are buggy as well..

*

* * Fri Jun 25 1999, Ingo Oeser

* –  Added strsep() which will replace strtok() soon (because strsep() is

*    reentrant and should be faster). Use only strsep() in new code, please.

*

* * Sat Feb 09 2002, Jason Thomas ,

*                    Matthew Hawkins

* –  Kissed strtok() goodbye

*/

// …….omit other……

// …… here is my love code  …..

#ifndef __HAVE_ARCH_STRCPY

/**

* strcpy – Copy a %NUL terminated string

* @dest: Where to copy the string to

* @src: Where to copy the string from

*/

#undef strcpy

char *strcpy(char *dest, const char *src)

{

char *tmp = dest;

while ((*dest++ = *src++) != ‘\0’)

/* nothing */;

return tmp;

}

EXPORT_SYMBOL(strcpy);

#endif

#ifndef __HAVE_ARCH_STRNCPY

/**

* strncpy – Copy a length-limited, C-string

* @dest: Where to copy the string to

* @src: Where to copy the string from

* @count: The maximum number of bytes to copy

*

* The result is not %NUL-terminated if the source exceeds

* @count bytes.

*

* In the case where the length of @src is less than  that  of

* count, the remainder of @dest will be padded with %NUL.

*

*/

char *strncpy(char *dest, const char *src, size_t count)

{

char *tmp = dest;

while (count) {

if ((*tmp = *src) != 0)

src++;

tmp++;

count–;

}

return dest;

}

EXPORT_SYMBOL(strncpy);

#endif

#ifndef __HAVE_ARCH_STRLCPY

#ifndef __HAVE_ARCH_STRNCAT

/**

* strncat – Append a length-limited, C-string to another

* @dest: The string to be appended to

* @src: The string to append to it

* @count: The maximum numbers of bytes to copy

*

* Note that in contrast to strncpy(), strncat() ensures the result is

* terminated.

*/

char *strncat(char *dest, const char *src, size_t count)

{

char *tmp = dest;

if (count) {

while (*dest)

dest++;

while ((*dest++ = *src++) != 0) {

if (–count == 0) {

*dest = ‘\0’;

break;

}

}

}

return tmp;

}

EXPORT_SYMBOL(strncat);

#endif

#ifndef __HAVE_ARCH_STRLCAT

// …….omit other……

// …… here is my love code  …..

The first time I looked at these codes with my classmates, he said: This is the code, and the others are s-h-x-t. Now I recall that when I implemented these codes, I wrote something I didn’t know what it was. Hey, code is more important than code~

Reading other people’s code is also a kind of progress and growth.

5、 Lian Po is old. Can you still eat?

According to the historical records Lin Xiangru biography of Lianpo, after he was dismissed, he went to the state of Wei. King Zhao wanted to use him again and sent someone to see his health. Guo Kai, Lianpo’s enemy, bribed the messenger. When the messenger saw Lianpo, Lianpo gave him a bucket of rice and ten kilograms of meat. He was mounted by armour to show that it was still usable. The messenger came back to report to King Zhao and said, “although general Lianpo is old and good at food, he can sit with his ministers. There are three dead arrows (common false words, namely shit).” King Zhao thought Lian Po was old, so he didn’t use it.

After decades of wind and rain, C language has countless scenery, and its figure can be seen everywhere in the world. However, in the eyes of some people, they may feel that C language is old (nearly 50 years old). As shown in the figure below:

If you really think so, you are wrong.

TIOBE Index for September 2020

The tiobe 2020-09 programming language ranking tells you that the C language is still a shining teenager.

 

What I want to say is that as long as the computer is still based on von Neumann architecture, the chip is still based on physical process. Then, there will be a C sky. Because she knows a place closest to the sky (C is one of the high-level languages closest to assembly and machine language).

I (C language) stand still as he changes the upper application Dynasty. This is C, the C language in my heart.

summary

Suddenly, I found that I had reached the conclusion, but I still felt that I still had more to say. This is not the most real her in my mind. However, I still hope that after reading this article, you can understand and be familiar with the beauty and reality of C.

 

Finally, I want to say: even thousands of words can’t say the importance of C language, and these words are only the tip of the iceberg.

In view of the limited personal ability, you are welcome to correct any problems or defects.

 

If you want to better improve your programming ability, learn C language and C + + programming well! Overtake at the corner, take a quick step!
C language c + + Learning Circle】, sharing (source code, project actual combat video, project notes, basic introductory tutorial)
Welcome to change careers and learn programming partners. Use more materials to learn and grow faster than you think!

Programming learning books:

 

Programming learning video:

 

Article source: https://mp.weixin.qq.com/s?__ biz=Mzg4NzU1MzIzMA==&mid=2247529947