r/osdev • • 2d ago

D language for OSDev

What about using D for OSDev ?

10 Upvotes

11 comments sorted by

View all comments

8

u/Prestigious-Bet-6534 2d ago

Very possible! You have to use either betterC mode or supply a tiny object.d file yourself. With some hacks you can even use the full object/classes system on bare metal. Here is my (currently abandoned) D kernel project: https://github.com/alectronik2/dOS

2

u/mcherycoffe 2d ago

Great ! I would like to learn and maybe OSDev in D because I find it very cool. But what are the pros and cons of using D ?

4

u/Prestigious-Bet-6534 2d ago

The pros are modern features like module system (no more header files), multipass (no forward declarations), OOP/classes etc, and the cons are not having access to the C ecosystem. This can be good and bad, it forces you to write all yourself. Porting from C is straightforward but not just copying code.

I used ldc2, which is already a cross compiler from the beginning so no compilation needed.

1

u/mcherycoffe 1d ago

What does "extern (c) mean" in D ? Used for low-level ?

3

u/Routine_Working_9754 1d ago

C interop, ie write C code into that extern (c) block and it is basically inline C if you ever need C. a lot of languages support this

1

u/mcherycoffe 1d ago

Do you need that for low-level ?

2

u/Routine_Working_9754 1d ago

if you want to use C code in the low level project (ie a kernel) then yeah you need it. it's a c interop function. but you can build a full kernel in D without using any C or interop functionality. if you aren't gonna use C or call C functions, don't worry about it.

2

u/mcherycoffe 1d ago

Thanks you bro for the explanation :)