LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 09-17-2005, 11:30 PM   #1
minike
Member
 
Registered: Aug 2004
Location: Argentina
Distribution: slackware 12
Posts: 211

Rep: Reputation: 30
Question C more common than C++ in linux?


hi everybody..
It's my first post in this forum, and I'm wonder -just an curiosity, why I see much more code in C than in C++
under linux..
If C++ got classes and all that 'advantages'.. why it isn't so used like C ?
regards.
 
Old 09-17-2005, 11:40 PM   #2
rshaw
Senior Member
 
Registered: Apr 2001
Location: Perry, Iowa
Distribution: Mepis , Debian
Posts: 2,692

Rep: Reputation: 45
the linux kernel is writen in c for starters.
 
Old 09-18-2005, 12:07 AM   #3
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Slightly off-topic, but anyway...

If a project as large and complex as the Linux kernel can be implemented as successfully as it has been in C, it makes me wonder if there's any real merit in coding in C++ in the first place. After all, the whole point of coding in an Object Orientated style is to make large, complex projects manageable.

Just a thought.

On the other hand, I know Not Much At All about kernel hacking, so maybe writing operating systems doesn't lend itself to OO programming.

It should be noted that I learned to program in Ada and Java, so I'm in no way a Procedural Language zealot, and I generally prefer programming in terms of objects.

Dave
 
Old 09-18-2005, 02:07 AM   #4
Harmaa Kettu
Member
 
Registered: Apr 2005
Location: Finland
Posts: 196

Rep: Reputation: 30
There are several reasons:
  • The advantages of c++ are smaller than you think. See the c++ chapter of "The Art of Unix Programming" for discussion about this.
  • Other languages (perl, java, python, PHP) have more advantages so they are used instead of c++.
  • Quality of the gcc c++ compiler used to be much worse than the c compiler. This probably isn't the case anymore, but many old projects use C because of it.
  • Writing portable c++ code is hard because every compiler (including different versions of gcc) supports different version of the language standard and different set of features.
Quote:
If a project as large and complex as the Linux kernel can be implemented as successfully as it has been in C, it makes me wonder if there's any real merit in coding in C++ in the first place. After all, the whole point of coding in an Object Orientated style is to make large, complex projects manageable.
Open source developers like to modularize their projects at higher level, splitting a complex project to multiple sub-projects. For example, in the Linux kernel each driver is a sub-project. This reduces complexity the same way as using OO.
 
Old 09-18-2005, 07:02 PM   #5
minike
Member
 
Registered: Aug 2004
Location: Argentina
Distribution: slackware 12
Posts: 211

Original Poster
Rep: Reputation: 30
very thanks 4 the answers
Harmaa: very interesting link .. I'm reading more than that article from such book.
fell now I know a little bit more..
 
Old 09-18-2005, 08:59 PM   #6
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
C++ is slower and produces larger binaries than straight C. I demonstrated this in another thread in this forum.

For system-level programming, C just makes more sense. It provides better access to the hardware and so forth.

Also, C is much more standardized and contains fewer extensions that are platform-dependent than C++.

On the flip side, C++ does have some nice toys for quick-and-dirty work. And C++ classes CAN be useful.
 
Old 09-19-2005, 07:08 AM   #7
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
GNOME is written in C, KDE uses C++. GNOME is considering to adopt a higher-level language for their project though.

IMHO C++ makes more sense for complex desktop applications, allowing programmers to think about more complex situations instead of worrying about low-level stuff. Background processes (think apache, sshd) perform many low-level tasks, C is a nice choice. For desktop appliations, problems like "how can I make two parts of my problem interact nicely?" arrise. C++ gives an answer for this. In effect, many users are able to create new kde applications, building on the development platform created by KDE.

KDE did suffer from the bad performance of C++ in the past, but they've also tracked the problems down to issues with GNU "ld" and "gcc". Improving the GNU stuff would fix many "C++ is slow" issues too. (gcc-3.4 already gives KDE more performance)

Last edited by yapp; 09-19-2005 at 07:11 AM.
 
  


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
BOGUS.common.04y -> /home/common/Mailbox jayakrishnan Linux - Networking 0 11-19-2005 04:48 AM
Common practices in Linux SoliTear Linux - General 5 01-09-2005 11:43 PM
linux windows common swap alaios Linux - General 3 09-26-2004 12:28 PM
Common filesystem for Linux and Windows? redneon General 9 05-22-2004 03:00 PM
linux nt domain common authentication masoooom Linux - Networking 0 08-25-2003 09:24 AM

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

All times are GMT -5. The time now is 12:55 AM.

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