Why are most Linux programs written in C?

There have been many discussions about this. Mainly, the reason is a philosophical one. C was invented as a simple language for system development (not so much application development). There are many arguments for using C++, but there are about as many for not using C++ and sticking to C.

In the end, it's a historical issue. Most application stuff is written in C, because most Kernel stuff is written in C. And since back then most stuff was written in C, people tend to use the original languages.

At this point, someone might ask "OK, so why is the kernel written in C and not ported to C++?". This has been discussed on kerneltrap some time ago. One nice explanation that can be quoted from this thread is a response by yoshi314 (quoting directly):

that's because nearly every c++ app needs a separate c++ standard library to operate. so they would have to port it to kernel, and expect an extra overhead everywhere.

c++ is more complex language and that means that compiler creates more complex code from it. because of that, finding that a problem stems from compiler bug,rather than code error is easier in c.

also c language is more barebone, and it's easier to follow its assembly representation, which is often easy to predict.

c++ is more versatile, but c is more suited for lowlevel or embedded stuff.


On the other hand, "most of Linux programs" is quite misleading. Take a look at graphical applications. Python is getting more and more ground especially in GUI environments on Linux. About the same thing that's happening with Windows and .NET.


After reading the following email from Linus Torvalds the creator of linux. I can't help thinking the answer above is incorrect. He seems to think that C++ programmers are not good systems programmers. And that the extra features in C++ often cause more problems in the long term compared to the benefits they bring in the short term. While one may disagree with him, it's difficult to overstate the influence he has had on the linux operating system.

http://harmful.cat-v.org/software/c++/linus

Tags:

Linux

C++

C