C++ or pure C for Linux kernel module, Linux device driver development. What to use?
C++ or pure C for Linux kernel module, Linux device driver development. What to use? What is mostly used?
In Internet I met many discussions. Many arguments for C and C++ Should we blindly follow what Linus said? Is Linux Kernel supposed to be ported to C++? What is mostly used C++ or C for kernel module development in open source and commercial development What do you know and herad and think about that question? What du you know about this C++ support http://netlab.ru.is/exception/LinuxCXX.shtml Thanks in advance |
Umm... what are you good at? Nobody is going to shoot you for writing a driver in C++. If you know how to code better at C++ then use it! Its very easy to link C++ code to C libraries, and I'm sure you can write inline ASM the same way you can in C. With that said I dont see any reason not to use C++, especially if its YOUR project. If others dont like the way you're doing things, tell them to write it their way and send you a patch. Most of them you wont hear from again ;)
|
Thanks But the kernel is compiled with gcc not g++ If I write in c++ I should compile them separately???
|
Well as I know, modules are simple .o (object files). So, it does matter if it's C or C++... you just need to tell gcc/g++ only to compile and not to link (man g++). Then you can insert the module in the kernel.
|
Not so fast... does the necessary programming-environment exist in the kernel-space environment? I don't know but I don't think that it does.
A kernel module becomes part of the kernel. It has no access to "runtime libraries," which is an essential part of the high-level niceities of a language like C++. |
You cannot write a kernel module in C++.
At least... not easily, and it isn't guarenteed to work. Quote:
|
What makefile should be for compilation of c++ kernel module
|
Read the LKML thread here: http://kerneltrap.org/node/2067
As the authors of http://netlab.ru.is/exception/LinuxCXX.shtml point out, their support ONLY works for i386 architecture. Unless your driver is i386 specific, then forget it. |
From what I read, the GCC compiler has incorporated some new features (C99) that adopted some changes from C++. There is a book by Novel on Linux kernel development that went into details in how the GCC compiler differs from vanilla C, but I don't remember the details.
|
Quote:
|
How to make Linux programming more comfortable
C++ is more efficient compiled than C now Maybe in 1992 it was Vice versa
????? |
Why do you think C++ compiler is more efficient? C++ adds a number of layers (read: more code) that's not needed (and wanted) at the kernel level.
|
Igor, can you demonstrate this?
My testing indicates a few things. First off, I used the defacto standards for output (printf in c, cout in c++), and attempted to create a relatively simple program. First off, the code: Code:
$ cat c_test.c Code:
$ gcc -o c_test c_test.c Code:
$ wc -l *.s Code:
$ wc -c *_test Code:
$ time ./c_test I welcome any studies to refute this. |
It is out of comparison
Matir
Iostream things of c++ is usage of library the big hierarchy of classes the huge code is added when the iostream things are used So it is out of comparison. Print functions can be used in C++ too. I mean the whole program code including many functions and data classes. Take emulated C class with function pointers and data and take c++ class with all these features. Some guys says that in general now C++ code is equally and sometimes is better compiled than C code. |
Again, prove your point please. I would leave to see such a demonstration.
|
All times are GMT -5. The time now is 06:35 AM. |