On Thu, Nov 25, 1999 at 01:53:32PM -0500, fred smith wrote:
> On Thu, Nov 25, 1999 at 10:53:13AM -0700, patrick wrote:
> > I have been wondering of late why it is that much of
> > the heart of linux and many linux apps are written
> > in c rather than c++.  Why is this?  Why not convert
> > everything over...presumeably c++ allows for tighter,
> > more efficient code.
> 
> Linux is written in C because, well, it's written in C. Given that
> it is a unix clone it seems appropriate.

You've pretty much hit the nail on the head.  There are many reasons
why it's written in C as apposed to anything else.   The top five
(in order of importance) would look something like this:

1) Unix == C, C == Unix.  They were both developed at the same time
and they fit together perfectly.  At the time most versions of Unix
were written, C++ was at best a pipe dream.  Even today, I don't think
we have a perfect standards compliant (we just got the standards
nailed down) compiler.

1a) People who have experience writing Unix OS's, generally write in
C (aka inertia).  Don't fix what ain't broken.

2) When you're writing hardware drivers and other code right next to
the bare metal, you don't want your compiler doing too much thinking
for itself.  The reason we use C is that one statement in C pretty
much corresponds to one assembly operation, and it's easy to mentally
picture in your head what your code is going to look like after it's
compiled.  With most other languages, C++ included, the compiler is
too smart.  C is almost too smart itself.  I normally use very simple
C syntax when I write device drivers.

3) C++ 'can' produce more efficient, leaner, code than C.  But only if
the programmer really knows C++ well, and the world currently has a
bad shortage of really good C++ programmers.  I'd guess that 90% of
people who consider themselves C++ programmers use MFC on a daily
basis, and that is not conductive to learning to write lean mean C++
code.

4) C++ has problems with object file compatability.  Every compiler
uses a different name mangling scheme which causes huge problems if
you try to link code that was compiled by two different compilers.
Unix doesn't need that kind of a headache in it's kernel and core
libraries.

5) C++, in the right hands, can produce better source and object code
than C.  But in the wrong hands it can also be abused much more than C
can (pointers to references to pointers, etc).

-- 
Steve Borho                       Voice:  314-615-6349
Network Engineer
Celox Communications Corp

Fortune of the day:
millihelen, n.:
        The amount of beauty required to launch one ship.


-- 
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.

Reply via email to