Java virtual machines and windows are both written in c ++. Why does linux kernel use c ++? Why do php interpreters and python interpreters use c instead of c ++? Does it mean php and python are simpler than Java virtual machines and linux is simpler than windows? Java virtual machines and windows are both written in c ++. Why does linux kernel use c ++? Why do php interpreters and python interpreters use c instead of c ++? Does it mean php and python are simpler than Java virtual machines and linux is simpler than windows? Reply: From a technical point of view:
From the grasp of compiled machine code, c is much better than c ++. System Programmers almost look at c and do not know the assembly code in the compiler. The c ++ compiler is much more complicated. an object's this pointer, coupled with various virtual tables, also has various copy structures. It is really not easy to fully control. (Although I have never written the operating system kernel, I always think that the operating system kernel should be controlled to compile, and c is only used to improve development efficiency .)
In terms of the advanced language features of c ++, do templates, polymorphism and other features be used in system development or not? This is a very practical problem. Unless these advanced features are well controlled, the compilation code expands, and the re-compilation causes strange problems. Kernel debugging is not the same as application debugging... Therefore, although bochs are converted to c ++, the template is not allowed in the development instructions.
The last point cannot be ignored. the Linux kernel is cross-platform. all platforms have corresponding C language compilers and should be well optimized. Instead of having c ++ compilers on all platforms, the efficiency of optimization is not always high.
Of course there are other factors, such as linus's personal likes and dislikes... 1. the Windows kernel is also C. A little bit of C ++ has been used in the past few years, but basically only C with class is used.
2. Linus personally hate C ++ very much.
3. Linux kernel was launched in 1991, and C ++ to 1998 was finalized.
4. whether the language is simple or not has nothing to do with writing. Operating system kernel is a few requirements
Clearly know what the computer is doingC is one of the few choices. The official answer from linus (although the original question was to ask why git was written in c instead of c ++, it also applies to the question subject based on the column ):
On Wed, 5 Sep 2007, Dmitry Kakurin wrote:> > When I first looked at Git source code two things struck me as odd:> 1. Pure C as opposed to C++. No idea why. Please don't talk about portability,> it's BS.*YOU* are full of bullshit.C++ is a horrible language. It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do *nothing* but keep the C++ programmers out, that in itself would be a huge reason to use C.In other words: the choice of C is the only sane choice. I know Miles Bader jokingly said "to piss you off", but it's actually true. I've come to the conclusion that any programmer that would prefer the project to be in C++ over C is likely a programmer that I really *would* prefer to piss off, so that he doesn't come and screw up any project I'm involved with.C++ leads to really really bad design choices. You invariably start using the "nice" library features of the language like STL and Boost and other total and utter crap, that may "help" you program, but causes: - infinite amounts of pain when they don't work (and anybody who tells me that STL and especially Boost are stable and portable is just so full of BS that it's not even funny) - inefficient abstracted programming models where two years down the road you notice that some abstraction wasn't very efficient, but now all your code depends on all the nice object models around it, and you cannot fix it without rewriting your app.In other words, the only way to do good, efficient, and system-level and portable C++ ends up to limit yourself to all the things that are basically available in C. And limiting your project to C means that people don't screw that up, and also means that you get a lot of programmers that do actually understand low-level issues and don't screw things up with any idiotic "object model" crap.So I'm sorry, but for something like git, where efficiency was a primary objective, the "advantages" of C++ is just a huge mistake. The fact that we also piss off people who cannot see that is just a big additional advantage.If you want a VCS that is written in C++, go play with Monotone. Really. They use a "real database". They use "nice object-oriented libraries". They use "nice C++ abstractions". And quite frankly, as a result of all these design decisions that sound so appealing to some CS people, the end result is a horrible and unmaintainable mess.But I'm sure you'd like it more than git.Linus
First, I want to start with two "long code" sections.
The following code is called min. c:
#include
/* * min()/max() macros that also do * strict type-checking.. See the * "unnecessary" pointer comparison. */#define min(x,y) ({ \ typeof(x) _x = (x); \ typeof(y) _y = (y); \ (void) (&_x == &_y); \ _x < _y ? _x : _y; })int main(void){ int a = 3, b = 5; double d1 = 3.14, d2 = 2.718; printf("min of a & b: %d\n", min(a, b)); printf("min of d1 & d2: %lf\n", min(d1, d2)); return 0;}
This problem also plagued me at the time. Why didn't C ++ be introduced in Linux kernel, and C ++ was used for rewriting, and a favorite answer was given.
The reasons specifically for Linux are explained in great detail aspart of the Linux Kernel Mailing List (LKML) Frequently AskedQuestions (FAQ) at: http://www.tux.org/lkml/Scroll down to section 15 (titled Programming Religion) and read theexplanation. A summary is: - Linus started with an 386 computer, Minix, and gcc (no g++ available) - C is used instead of Assembly for a LOT of reasons (maintenance,readability, efficiency, ...) - it is not clear how an object oriented language helps in OS design - MANY years ago, they tried using g++ to compile the Linux kerneland found it ran slower than when compiled with gcc (many thought itshould have been the same); they are not willing to do this again - Linus makes the final decision and he's decided to stick with CThere is also another good explanation of some of the issues at http://kerneltrap.org/node/2067which describes one person's attempt to build adapt some C++ code toincorporate into a kernel module.For a historical perspective, Thompson and Ritchie developed Unixusing some of the concepts from Multics and CTSS http://www.multicians.org/unix.htmlincluding implementation of most operations in a higher order language(Unix - C, Multics - PL/I), common naming of commands, etc. I alsorefer you to http://cm.bell-labs.com/cm/cs/who/dmr/hist.htmlwhich describes the EARLY development of Unix including the conversionfrom Assembly on the PDP-7 to C on the PDP-11 (near the end of thepaper).Building from that basis, the Unix from AT&T that was widelydistributed and worked on by thousands of people was a C basedoperating system. In the 1970's and 1980's, an alternative to AT&T'sdistribution was developed at UC Berkeley, see http://en.wikipedia.org/wiki/Berkeley_Software_Distributionfor a relatively short explanation of the development of BSD. The BSDversion eventually did not use ANY of the AT&T code base, but was alsoimplemented in C. At the end of the article is a list of several BSDdescendants including SunOS (now Solaris).That is not to say that some applications are better implemented in anOO language such as C++. There are several Graphical User Interface(GUI) toolkits such as KDE which are implemented in C++. However,there are applications that are better suited for a more procedurallanguage, and at this point operating systems are in that category.If this answer is unclear or somehow incomplete, please make aclarification request.Good luck with your work. --Maniac
Linus does not like C ++ at the lower layer, which is more reliable and stable. Ask Linus, and see if he will blow your face (straight-forward). Objective c ++ is too free. Are you sure you want to write the operating system kernel?