tags:

views:

446

answers:

8

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

+3  A: 

I don't know which system calls you're referring to, but I bet that most UNIX-ee operating systems are coded in straight C. There's probably just C++ wrappers for the system calls.

jdizzle
A: 

UNIX systems are generally coded in straight C and for some reason most UNIX developers also seem to dislike C++.

Tronic
AFAIK C++ wasn't around when a great deal of the core UNIX kernel was built, but even ignoring that C has a standard ABI, which C++ lacks. This makes compatibility between disparate bits of the system much easier. It's not that they "dislike" C++, it's just that there are historical and technical reasons for choosing C.
Toji
Well, Linus Torvalds dislikes C++, but that matters only for one (admittedly very important) system. I don't know how many other people who develop on Unix on various levels dislike C++. Some do, many don't.
David Thornley
@David: though he doesn't seem to have done a lot of development recently at all, Eric S. Raymond's opinion seems fairly influential, and a few of his many diatribes have been (mostly ill-informed nonsense) about (supposed) problems in/with C++. http://esr.ibiblio.org/?p=532
Jerry Coffin
@Toji:C doesn't really have a standard ABI. What it has is minimal requirements, so designing an ABI for it on any given hardware is often pretty easy. Once the primary vendor designs one, most others typically follow it. With C++ the ABI takes more work, and gives more opportunity for differences.
Jerry Coffin
@Jerry: Makes sense. Practical result is still that interoperability is much easier, though, so I'm all for it no matter how it happened! :)
Toji
A: 

kernel is in c; majority of programs/libraries are also in c.

do you have any programming question?

fazo
Most of my desktop is C++ (KDE, firefox).
Johannes Schaub - litb
The assertion about "the majority of programs/libraries" is very questionable.
bortzmeyer
Well I was referring to the Open API in UNIX V...
Zero Cool
+11  A: 

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...

DigitalRoss
To clarify, the C++ in Mac OS X is only for IOKit, the device driver interface. The Mach and BSD layers are straight C.
gavinb
I knew about IOKit but didn't know if C++ was used elsewhere. Thanks for the note; I've adjusted the wording slightly.
DigitalRoss
+5  A: 

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.

Bob Murphy
+1  A: 

Definitely C - try man syscall or man -s2 read - that gives you C library interface, no C++ in sight.

Nikolai N Fetissov
+14  A: 

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++.

mctylr
In fact, UNIX was created (1969) _before_ even C was (1972) conceived. According to Wikipedia, original UNIX was written in PDP-11/20 assembly language, then in 1973 rewritten in C.
el.pescado
Yes, almost. The original Unix was written (1968-9) in PDP-7 assembly, on a 8 kiloword PDP-7. Unix was ported to the PDP-11 assembly when Bell purchased a PDP-11/20 in 1970, and later Unix was rewritten in C in 1973 while still on the PDP-11. Src: Dennis Ritchie http://cm.bell-labs.com/cm/cs/who/dmr/chist.html
mctylr
A: 

A few OS kernels have been written in C++. I believe the Chorus kernel (for one example) is written (almost?) exclusively in C++ (it's somewhat like Mach: a microkernel that's used almost exclusively via a UNIX emulator running as a user-mode server).

There have been a few other semi-experimental systems in C++ as well. One fairly recent one is named Hybrid. A much older one was posted on comp.sources.misc (in four consecutive posts) years ago -- I'm pretty sure it'd take a fair amount of work to get it to compile with a current C++ compiler. This one runs on a virtual machine, and includes source to emulate the hardware.

Jerry Coffin