• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Main advantages to using C/C++ for device drivers?

Quad

Golden Member
Hi,

What are the main reasons for using C (or C++) for writing things like device drivers and even operating systems. Why not use something like Java? (I'm not saying we should use Java, but I'm just wondering why C/C++ are mainly used)

Thanks!
 
If I remember Correctly, the main reasion that C and C++ are used is their speed and flexability. Java has gotten faster, but the origional was very slow. Another possible reasion is that C and C++ have been around longer then java and have just melted into the standard.
 
Java is interpreted in real-time, C and C++ are compiled. For something like an operating system, it's easier not to have to bootstrap a JRE on top of the hardware; with a kernel written in C, it just runs directly.

And besides the performance concerns (although it's better than it used to be, especially for non-graphical things), interfacing with hardware at a very low level is harder to do in Java than in C. You can mix assembler code freely into C/C++ functions, which you can't do with Java.
 
A driver is a piece of code that connects a piece of hardware to an operating system. C/C++ code complies to assember for a particular OS. Java requires a runtime environment to be interpreted or be just-in-time compiled. For hardaware that needs to run fairly fast, like a sound or video card, performance would drop signifigantly.

Furthermore, Java doesn't bind very well to hardware (assembler) requirements like addresses in pointers and interrupts. Even if it did, there's a chance Java wouldn't offer what your hardware needs from a driver perspective.

But worst of all, also there's a problem of support. Java is _supposedly_ "write once, run anywhere." Hah, it's more like write once, break everywhere. It ideally runs on all hardware with a compatible run-time environment. But reality is not ideal, each platform has to implement the runtime, and there can be differences, even pieces not implemented yet. And if a bug fix changes the runtime down the road, it may break your driver, even though you are running on the same hardware. Imagine installing a service pack then not being able to boot because some of your drivers are hosed. Complied code that does not use a runtime would never have this problem.

Bottom line: C/C++ .is stabler and faster than Java. Java is good for applications (particularly web-based) but C is king of system-level code.
 
Back
Top