LinuxQuestions.org
Help answer threads with 0 replies.
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 10-01-2009, 06:25 PM   #1
Guptarulz
LQ Newbie
 
Registered: Oct 2009
Posts: 16
Blog Entries: 1

Rep: Reputation: 1
C or C++ for Linux kernel Programming


Hi All,

I am new to linux kernel programming. I need to implement some OS kernel bases code. I want to know which one to choose for the programming C or C++. I am inclined to use C++ as this give me code more modularity and OOPs concepts.

Is all the libraries of kernel also available in C++?

Can some one suggest some IDE for this ?

Thanks
 
Old 10-01-2009, 06:26 PM   #2
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,220

Rep: Reputation: 164Reputation: 164
you can use C++ if you cut it back to the basic
so freaky dirived and virtual classes and stuff
because all that will have a speed inpact and maybe generate incompatable code
C would be more suited but C++ is fine AFAIK
 
Old 10-01-2009, 06:37 PM   #3
Guptarulz
LQ Newbie
 
Registered: Oct 2009
Posts: 16
Blog Entries: 1

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by smeezekitty View Post
you can use C++ if you cut it back to the basic
so freaky dirived and virtual classes and stuff
because all that will have a speed inpact and maybe generate incompatable code
C would be more suited but C++ is fine AFAIK
I am not concerned about the speed the main thing is that how easy is to code on C++
 
Old 10-01-2009, 06:39 PM   #4
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,220

Rep: Reputation: 164Reputation: 164
coding is always alittle on the harder side in the kernel
i know because the tweeked the $h!t out of the linux kernel
and i am writing my own kernel
 
Old 10-01-2009, 06:55 PM   #5
Guptarulz
LQ Newbie
 
Registered: Oct 2009
Posts: 16
Blog Entries: 1

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by smeezekitty View Post
coding is always alittle on the harder side in the kernel
i know because the tweeked the $h!t out of the linux kernel
and i am writing my own kernel
Is this same for C and C++ both?
Can I do one thing write some code in C and some in C++?
 
Old 10-01-2009, 06:58 PM   #6
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,220

Rep: Reputation: 164Reputation: 164
yes
you just dont quite as many services and functions as in user mode
 
Old 10-02-2009, 11:50 AM   #7
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 114Reputation: 114
You cannot use any libraries in the kernel, period. None are supported.

You can use C++ if you wish, but you have to make sure your bindings to the kernel are C style because that is what the kernel is written in.

Normally I handle this type of issue by running through some C stubs that are compiled with gcc and that call my C++. Of course, normally I do all my kernel work in C.
 
Old 10-02-2009, 06:47 PM   #8
orgcandman
Member
 
Registered: May 2002
Location: dracut MA
Distribution: Ubuntu; PNE-LE; LFS (no book)
Posts: 594

Rep: Reputation: 102Reputation: 102
NO!

You cannot use C++ in the linux kernel without a lot of work, and frankly that work doesn't reward with much benefit.
C++ implicitly looks for certain bindings to be available. From casts to constructors, C++ just isn't designed to be a kernel language. There's a famous example somewhere of an attempt to do it, but it was really cumbersome and never went anywhere, IIRC.
 
Old 10-02-2009, 08:23 PM   #9
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by Guptarulz View Post
Hi All,

I am new to linux kernel programming. I need to implement some OS kernel bases code. I want to know which one to choose for the programming C or C++. I am inclined to use C++ as this give me code more modularity and OOPs concepts.

Is all the libraries of kernel also available in C++?

Can some one suggest some IDE for this ?

Thanks
Once you are ready to write kernel code, you will know the answer to this question. Virtually none of the Linux kernel is written in C++, because the programming style is very low-level, almost like assembly.

And your question about availability of kernel libraries "also" in C++ speaks volumes. Programs written in C aren't trivially translated into any other language (except, of course, into machine-specific code by the compiler).

Why not just download the kernel source and browse through it? It's not like it's a nuclear secret.
 
Old 10-03-2009, 05:23 AM   #10
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 114Reputation: 114
Quote:
Originally Posted by orgcandman View Post
NO!

You cannot use C++ in the linux kernel without a lot of work, and frankly that work doesn't reward with much benefit.
C++ implicitly looks for certain bindings to be available. From casts to constructors, C++ just isn't designed to be a kernel language. There's a famous example somewhere of an attempt to do it, but it was really cumbersome and never went anywhere, IIRC.
This has been almost a religious debate, and I won't get involved...

I believe that it IS possible to write kernel code in C++, so long as the C bindings are preserved and no libraries are invoked. Is it a good idea? Probably not. The kernel is written in C and the prudent developer will stick with that.
 
  


Reply

Tags
c++


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Linux Kernel Programming ganeshbonal Programming 10 09-15-2008 04:49 AM
linux kernel programming hoshangi Programming 1 08-31-2008 10:20 AM
Linux kernel debugging and Linux kernel module programming Igor007 Programming 2 08-13-2005 05:12 AM
Linux kernel debugging and Linux kernel module programming Igor007 Linux - Enterprise 3 08-12-2005 02:47 PM
linux kernel programming sonika_singhi Programming 9 12-22-2004 04:59 PM


All times are GMT -5. The time now is 02:33 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration