Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kernel development and C++ [closed]

From what I know, even though the common OS have parts written in other languages, the kernel is entirely written in C.

I want to know if it's feasible to write a Kernel in C++ and if not, what would be the drawbacks.

like image 981
coredump Avatar asked Sep 12 '12 09:09

coredump


People also ask

Why is C++ not used in kernel development?

Traditionally, the arguments against using C++ in kernel code have been: Portability: availability of C++ compilers for all intended target platforms. This is not really an issue any more. Cost of C++ language mechanisms such as RTTI and exceptions.

Why C is used in kernel?

The C language was actually created to move the UNIX kernel code from assembly to a higher level language, which would do the same tasks with fewer lines of code. Oracle database development started in 1977, and its code was rewritten from assembly to C in 1983.

What is kernel programming in C?

The kernel is written in the C programming language [c-language]. More precisely, the kernel is typically compiled with gcc [gcc] under -std=gnu11 [gcc-c-dialect-options]: the GNU dialect of ISO C11. clang [clang] is also supported, see docs on Building Linux with Clang/LLVM.

How is a kernel developed?

The kernel is written using GNU C and the GNU toolchain. While it adheres to the ISO C89 standard, it uses a number of extensions that are not featured in the standard. The kernel is a freestanding C environment, with no reliance on the standard C library, so some portions of the C standard are not supported.


1 Answers

This is covered explicitly in the OSDev Wiki.

Basically, you either have to implement runtime support for certain things (like RTTI, exceptions), or refrain from using them (leaving only a subset of C++ to be used).

Other than that, C++ is the more complex language, so you need to have a bit more competent developers that won't screw it up. Linus Torvalds hating C++ being purely coincidental, of course.

like image 87
DevSolar Avatar answered Sep 23 '22 17:09

DevSolar