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

后端 未结 15 2362
庸人自扰
庸人自扰 2020-12-14 00:22

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.

15条回答
  •  青春惊慌失措
    2020-12-14 00:34

    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.

提交回复
热议问题