ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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++?
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339
Rep:
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
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++
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.