LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   C or C++ for Linux kernel Programming (http://www.linuxquestions.org/questions/programming-9/c-or-c-for-linux-kernel-programming-759092/)

Guptarulz 10-01-2009 06:25 PM

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

smeezekitty 10-01-2009 06:26 PM

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

Guptarulz 10-01-2009 06:37 PM

Quote:

Originally Posted by smeezekitty (Post 3704317)
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++

smeezekitty 10-01-2009 06:39 PM

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

Guptarulz 10-01-2009 06:55 PM

Quote:

Originally Posted by smeezekitty (Post 3704332)
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++?

smeezekitty 10-01-2009 06:58 PM

yes
you just dont quite as many services and functions as in user mode

jiml8 10-02-2009 11:50 AM

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.

orgcandman 10-02-2009 06:47 PM

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.

lutusp 10-02-2009 08:23 PM

Quote:

Originally Posted by Guptarulz (Post 3704315)
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.

jiml8 10-03-2009 05:23 AM

Quote:

Originally Posted by orgcandman (Post 3705604)
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.


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