Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Why most of linux programs are written in C? Why they are not written with C++ which is newer than C?

share|improve this question
8  
C++ is newer than C, but that's a bit irrelevant. They are different languages. –  Mat Oct 30 '11 at 18:27
5  
You should probably ask this at StackOverflow or Programmers (where the topic has actually been already nicely covered). –  rozcietrzewiacz Oct 30 '11 at 18:29
2  
@Mat Well, it's not entirely correct, as C++ is a superset of C. You can program in C and compile it with a C++ compiler. It'll compile and work as expected. –  polemon Oct 30 '11 at 23:56
5  
@polemon: that's incorrect, there are incompatibilities. en.wikipedia.org/wiki/Compatibility_of_C_and_C%2B%2B –  Mat Oct 31 '11 at 5:25
add comment

1 Answer 1

up vote 12 down vote accepted

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.

share|improve this answer
2  
Additionally the C have stable ABI and can be easily plugged to other languages via their native FFI while C++ does not have human-readable ABI and g++ had changes in the ABI. Therefore the libraries tended to be written in C rather then C++. Because you want to have one language in project so did the programs bundled with library. (At least that was a story with Gnome). –  Maciej Piechotka Oct 30 '11 at 23:33
    
@MaciejPiechotka All this is true, and it is a nice discussion, but c doesn't have a defined ABI, except that there is often a "obvious" way to work things on each platform. After that it's follow the leader. –  dmckee Nov 1 '11 at 0:34
    
@dmckee: I haven't stated it has standardized but C API on each platform follows certain simple rules (including no or minimal mangling) which rarely changes - which makes it useful for the purpose even if not 100% correct. –  Maciej Piechotka Nov 1 '11 at 13:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.