LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-24-2005, 11:26 PM   #1
Jatinm
LQ Newbie
 
Registered: Jan 2005
Location: India
Posts: 2

Rep: Reputation: 0
Question Why LInux is Written in C and in C++?


I just wonder why Linux is written in C and not in C++. Is there any logical reasoning for this or its just the popularity of C which made the selectio of the language?
 
Old 01-25-2005, 12:02 AM   #2
rgiggs
Member
 
Registered: Apr 2004
Location: berkeley, ca
Distribution: slk10, winxp
Posts: 313

Rep: Reputation: 30
i guess it makes sense because unix is c, and c is probably the only practical language above assembly with which to program an operating system. though you still need some assembly in the kernel.
i'm not aware of any practical general purpose kernel that is written in any thing other than c.
also i think c++ is too dirty, or not as clean as c.

Last edited by rgiggs; 01-25-2005 at 12:07 AM.
 
Old 01-25-2005, 01:03 AM   #3
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 01-25-2005, 06:35 AM   #4
zaichik
Member
 
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Rep: Reputation: 30
I would think it's mostly a matter of timing. If you think about it, C++ first showed on the radar screen in 1985. I am unsure when Torvalds began linux development, but at least parts surfaced in 1991. It is quite likely that he wasn't familiar with C++, or at least not enough to use it as well as the well-established C.

Cleaner? I don't know, I guess it depends what you're used to. I prefer Strings to char* but that is just a personal preference.
 
Old 01-25-2005, 07:28 AM   #5
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
And portability is a very important reason, too.
 
Old 01-25-2005, 09:27 AM   #6
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
First link from a google search:
http://kerneltrap.org/node/2067?PHPS...7ef71a854302f2

Quote:
During the recent discussion, when it was suggested that perhaps the kernel is written in C simply because "we've always done it that way...", Linux creator Linus Torvalds joined in to explain:

"In fact, in Linux we did try C++ once already, back in 1992. It sucks. Trust me - writing kernel code in C++ is a BLOODY STUPID IDEA.

"The fact is, C++ compilers are not trustworthy. They were even worse in
1992, but some fundamental facts haven't changed: 1) the whole C++ exception handling thing is fundamentally broken. It's _especially_ broken for kernels. 2) any compiler or language that likes to hide things like memory allocations behind your back just isn't a good choice for a kernel. 3) you can write object-oriented code (useful for filesystems etc) in C, _without_ the crap that is C++."
 
Old 01-25-2005, 10:15 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
hear hear!
 
Old 01-26-2005, 01:20 AM   #8
rgiggs
Member
 
Registered: Apr 2004
Location: berkeley, ca
Distribution: slk10, winxp
Posts: 313

Rep: Reputation: 30
he he he i told you c++ was dirty. personally, i think things like the dynamic/static/const... casts are dirty.
and you know if you allocate objects dynamically (using new), then you have to call delete on them to invoke the destructor. so what if you forget to delete -> memory leak, see? and then to "solve" that problem, they introduced the --what is it? i don't remember what they're called anymore-- safe pointer or something. and the safe pointers are instantiated statically, so the destructor is invoked automatically when the safe pointer goes out of scope. but then there's this issue of "the owner" of the memory that the safe pointer points to. blah blah blah. it's a mess.

Last edited by rgiggs; 01-26-2005 at 01:22 AM.
 
Old 01-26-2005, 03:27 AM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
not to mention 'friends'.
what's that all about?
 
Old 01-26-2005, 03:55 AM   #10
rgiggs
Member
 
Registered: Apr 2004
Location: berkeley, ca
Distribution: slk10, winxp
Posts: 313

Rep: Reputation: 30
Quote:
Originally posted by bigearsbilly
not to mention 'friends'.
what's that all about?
sorry. i'm lost. what do you mean? what are you referring to?
 
Old 01-26-2005, 03:59 AM   #11
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
those horrible 'friend' functions
where you can access private data in classes or
something.
yukky
A real botch job.
 
Old 01-26-2005, 10:34 AM   #12
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
I admire Linus Torvalds and George Lucas a lot (what? How could I put both in the same sentence... I will explain ). But I just don't know... sometimes they are a bit full of crap: "I've tried to program Linux with C++" and "I've planned Jar Jar Binks in the 70's", sounds suspicious.

I for one, believe that a kernel written in C++ would be still fast and easier to maintain. And just because it's C++, it does not stops you for using anything for C...

Again, I admire Linus for creating Linus (even though, the current kernel is only 2% written by him) and George Lucas for creating a huge, deep world as Star Wars (even though, his new movies with computer graphics looks horrible) but when they are talking things from the past like this, finding excuses for that... smells like Bantha podoo for me...
 
Old 01-26-2005, 12:14 PM   #13
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
I can tell you from experience that C++ is a lot bloatier than an application that does the same thing in C.

It's not a question of whether or not C++ is fast. It's a question of whether or not C++ is faster than C, and if it's worth the trouble to rewrite the entire kernel (which means introducing new bugs, etc.) Linus has stated before that if they switch to a C++ kernel that they'd do it all or nothing. They wouldn't start writing little bits at a time in C++ and tie it into other C code.

Last edited by itsme86; 01-26-2005 at 12:29 PM.
 
Old 01-29-2005, 06:12 AM   #14
Jatinm
LQ Newbie
 
Registered: Jan 2005
Location: India
Posts: 2

Original Poster
Rep: Reputation: 0
Thank you all for your valuable responses and information. I think there is no strict reason why C++ is not used, but the time as C was very popular and stable at the time when Linux was developed.
Thanks all.
 
Old 01-29-2005, 10:42 AM   #15
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
And still is !
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
creating partitions that can be written to by both windows and linux aitzim SUSE / openSUSE 11 10-26-2005 06:43 AM
windows can't see the files written by linux feetyouwell Linux - Software 10 02-12-2005 07:59 AM
have you ever written a program for linux? today53 General 33 12-05-2003 06:54 PM
Linux written in Visual Basic?!?!?!? newmodel15 General 21 08-23-2003 10:29 AM
what are the files written by linux OS while running vaibhavk Linux - General 2 01-17-2002 11:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration