Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Unix coded in C or C++ or both?

Tags:

c++

c

unix

Many system calls in Unix use overloading and default variables. This concept is absent in C, so Unix is coded in C++ also right?

like image 903
KnightScott Avatar asked Mar 07 '10 03:03

KnightScott


People also ask

Is Linux written in C?

Most of the operating systems are written in the C/C++ languages. These not only include Windows or Linux (the Linux kernel is almost entirely written in C), but also Google Chrome OS, RIM Blackberry OS 4.

Is C same as Unix?

These are two different Entities. UNIX (Uniplexed Information Computer Service,UNICS) is an operating system. Whereas C Language is well a “programming” language. A High-Level, general purpose programming language used for developing firmware or portable applications.

Is Unix coded in C?

The UNIX operating system's development started in 1969, and its code was rewritten in C in 1972. The C language was actually created to move the UNIX kernel code from assembly to a higher level language, which would do the same tasks with fewer lines of code.


3 Answers

Unix was first created at Bell Labs in 1969, well before C++ was conceived. (Src: Unix), you can confirm this by reading Lions' Commentary on Unix, or the BSD 4.4-Lite (which is similar to BSD Net/2) which is available in tarball or via cvs (from FreeBSD). Or the archives from The Unix Heritage Society which is from the very old Bell Labs / AT&T versions.

Bjarne Stroustrup created C++ in approximately 1983, prior to that he worked on "C with Classes", according to History of C++. Confirmed from Bjarne Stroustrup's FAQ, and the earliest date for C with Classes was 1979.

I hope that clarifies the impossibility of the idea that Unix was based upon C++. Note that Object-Oriented languages have been around since 1960s in Simula 67, so don't confuse objects and classes with C++.

like image 162
mctylr Avatar answered Nov 04 '22 09:11

mctylr


Pretty much straight C all the way down...

All major versions of Unix use entirely straight C for the kernel. (Well, Mac OS X has a little C++ in one interface.)

If you don't count the desktop layer, then without more than a few exceptions, the core libraries and utilities are in C as well. The only core utility that I can think of that is written in C++ is groff.

Now, with packages, it's a different story...

like image 21
DigitalRoss Avatar answered Nov 04 '22 11:11

DigitalRoss


When you talk about kernels for Unix-y operating systems like Linux, Solaris, Mac OS X, NetBSD, FreeBSD, etc. - they're typically all C. And I also am not sure what you mean by overloading or default variables - certainly not in kernel calls.

I was surprised when DigitalRoss said Mac OS X has Objective C in the kernel sources, so I downloaded the MacOS X 10.6.2 version of the Darwin xnu kernel sources, and indeed, there was no Objective C. I was, however, slightly shocked to discover a little C++.

Anyway, a lot of things "user-space" (non-kernel) programs rely on, like virtual memory, exception handling, device I/O, and so on, are done by the kernel. But the kernel can't use itself for those things, just like you can't lift yourself up in the air by picking up your shoes with your hands.

Object-oriented languages like C++ and Objective C make extensive use of exactly the things kernels can't do for themselves. That's why kernels are mostly written in C. In the case of that C++ I saw in the xnu sources, I'm sure it's very, very carefully written to avoid doing things that aren't safe in the kernel.

As far as user-space programs being written in C vs. C++, I think it's mostly tradition, personal preference, and what people are used to. As someone who's proficient in both languages, I think it's rather silly myself.

like image 37
Bob Murphy Avatar answered Nov 04 '22 10:11

Bob Murphy