Re: writing drivers using C++
- From: Wolfgang Draxinger <wdraxinger@xxxxxxxxxxxxxxxx>
- Date: Sat, 08 Sep 2007 01:20:16 +0200
RRC wrote:
Is it possible to write device drivers using C++ programming?
If you're willing to provide the neccesary infrastructure: Yes.
I've read a lot of awnsers on using C++ in the kernel here, some
are going into the right direction, but none got it right.
Let's get this straight: There's only very little runtime support
nedded for C++. Those are:
* calling constructors of globally declared, statically
instanciated class instances
* cast operators
* new and delete operators
All the other things can be perfectly done at compile time.
Polymorphism internally works much like e.g. the fops structure
used to implement inode syscalls.
In C++ each class instance carries a table (or a pointer to that
table) of function pointers to virtual functions. By inheriting
from a class, all the entries in these tables are inherited,
too, but those functions that are overridden replace those
entries in the derived table. Similairily you can create fops
structures that share a subset of syscalls, while descendants
differ.
If one got enough discipline he can do OOP perfectly with a
language like C. Just look at the GObject system. Or the Linux
kernel, which internally uses a lot of OOP concepts, only that
those things are done "manually" using structs and macros.
But if one would like to he could patch the GCC to do C++ stuff
using custom runtime functions, that are also linked into the
kernel. Then add some extra spice into the module init part (to
get static class instances properly initialized) and there you
are: C++ support for kernel programming.
In case you wonder why it's not done in Linux, simple reason:
Sometimes C++ can be a pain in the a*** if you have to get
something done very low level or to utilize a dirty trick. And
it makes dealing with binary objects a whole lot more
complicated, especially if you've to deal with different
compiler versions (there is no strict C++ ABI, yet).
Wolfgang Draxinger
--
E-Mail address works, Jabber: hexarith@xxxxxxxxxx, ICQ: 134682867
.
- Follow-Ups:
- Re: writing drivers using C++
- From: phil-news-nospam
- Re: writing drivers using C++
- From: Ulrich Eckhardt
- Re: writing drivers using C++
- References:
- writing drivers using C++
- From: RRC
- writing drivers using C++
- Prev by Date: kernel threads and signals
- Next by Date: Re: writing drivers using C++
- Previous by thread: Re: writing drivers using C++
- Next by thread: Re: writing drivers using C++
- Index(es):