Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are drivers and firmwares almost always written in C or ASM and not C++?

Tags:

c++

c

I am just curious why drivers and firmwares almost always are written in C or Assembly, and not C++?

I have heard that there is a technical reason for this.

Does anyone know this?

Lots of love, Louise

like image 440
Louise Avatar asked Jan 11 '10 01:01

Louise


People also ask

Are drivers written in C or C++?

Writing a DriverDevice drivers are typically written in C, using the Driver Development Kit (DDK). There are functional and object-oriented ways to program drivers, depending on the language chosen to write in. It is generally not possible to program a driver in Visual Basic or other high-level languages.

Are Linux drivers written in C?

The Linux kernel is written in the C and Assembler programming languages. C implements the main part of the kernel, while Assembler implements architecture-dependent parts. That's why we can use only these two languages for Linux device driver development.

What are drivers written in?

Drivers are written in C or restricted subsets of C++ on all production-grade server, desktop, and mobile operating systems. They account for 66% of the code in Linux, but 39 out of 40 security bugs related to memory safety found in Linux in 2017 are located in drivers.

Are writing drivers hard?

Writing a simple device driver is difficult enough, and if you're talking about something complex—well, let's just say that not even major companies always get it right. This area of software development is specific and detached, requiring its own techniques, processes, and specialists.


1 Answers

Because, most of the time, the operating system (or a "run-time library") provides the stdlib functionality required by C++.

In C and ASM you can create bare executables, which contain no external dependencies.

However, since windows does support the C++ stdlib, most Windows drivers are written in (a limited subset of) C++.

Also when firmware is written ASM it is usually because either (A) the platform it is executing on does not have a C++ compiler or (B) there are extreme speed or size constraints.

Note that (B) hasn't generally been an issue since the early 2000's.

like image 173
John Gietzen Avatar answered Sep 25 '22 06:09

John Gietzen