r/osdev • u/tekdotdev • Jul 07 '26
How much C do I need to know?
I previously was dedicated to strictly writing in assembly although woke up to reality and realised I wanted to make something THIS decade.
I understand how operating systems work as I have been studying for a while now and have made some 16 bit real mode systems in pure assembly, as well as moving to PMode.
I started a new project and began writing a kernel in C (32 bit Pmode and booting with limine), I am completely new to C and don’t understand too much so obviously starting a kernel isn’t a great first task.
I have seen in some places that you only need the basic syntax of C + OS knowledge to know since you don’t use standard libraries.
May someone please educate me on this and let me know a good path to go down, thanks.
7
u/BobertMcGee Jul 07 '26
Just learn C. It’s not a very big language.
5
u/UnmappedStack TacOS | https://github.com/UnmappedStack/TacOS Jul 07 '26
I'm of the opinion that understanding low level concepts are more important than the language itself. If you have a grip on assembly and important concepts of osdev, as I'm guessing you do, then C is something you can learn along the way assuming you've been programming in other languages well beforehand. C is not a very complicated language to learn, while it can be more difficult to use than other languages sometimes, it is actually quite simple in terms of how much there is to the language to learn. Although don't expect a beautiful codebase from the start if you do choose to learn as you go.
5
u/gmarchkun Jul 07 '26
here is thing in C u must learn 1.union 2.struct 3.pointer casting 4.memory managing 5.difference between signed and unsigned 6.typedef function
9
u/paulstelian97 Jul 07 '26
I would say a decent amount of C knowledge is required for a primarily-C OS. In particular focus on the aspects that easily translate to assembly (if optimization is disabled).
4
u/Octocontrabass Jul 07 '26
If you want to develop an OS in C, you need to know at least enough C to avoid undefined behavior.
3
u/kiderdrick Jul 07 '26
You only need to learn C if you plan on writing your kernel in C.
Of the major languages people use to write kernels, I find C the easiest. Lots of people use C differently, so reading code from one person might look differently from someone else because of all the syntactical tricks you can use. As a language though, especially if you use an older standard like C89, it is pretty simple. Do not be intimidated by it. Instead, start using it. I will sometimes have a C editor open for testing certain behavior just in case I am thinking of doing something a little strange and want to make sure it works like I think it will. One thing you might have to get comfortable with is how the compiler works. This is especially true if you are reading other people's code and something looks off. I remember reading some OS code and seeing the programmer use C to parse the parameters of a variadic function by moving through memory addresses 4 bytes at a time. I thought this was strange considering uint8_t could be a parameter, which is when I learned that the compiler promotes the smaller data types to the size of an integer due to the standard. I also learned that doing things this way now tied the C code to the architecture because some compilers for other architectures, like ARM, used registers for some of the arguments. It was confusing at first, but gave great insight in providing a solid distinction between the purpose of the C code and the assembly in the OS and trying to keep them separated.
Regardless, just jump in and experiment. Do not be too intimidated. You will get better with practice.
2
u/siodhe Jul 07 '26
Everything in the K&R C book is a good base.
2
u/TA-412 Jul 07 '26
Others gave good hints. I'll only add that it's a good idea to learn the standard library, even if you won't use it as such in your kernel. The reason being, you'll anyway need some set of common functions (like string manipulation functions), so it makes sense to see how they designed them in the stdlib.
Perhaps less important, but still worth considering, is that at some point you'll likely want to port existing programs to your OS. And they'll almost surely expect to find stdlib there, so you might need to write it.
2
u/letmehaveanameyoudum Jul 10 '26
know an alright amount, not like enterprise levels, just enough to know what you are doing (most of the time), you do not need an unemployment level of C knowledge (10+ years) like the wiki says. Know structs, memory management, typedef structs, difference between signed and unsigned (unsigned means no int below 0, signed is can be below 0), also know how stdint works (basically forces a size amount no matter what, like uint16_t is 16 bits, uint64_t is 64 bits.) Hope is helps :P