Is C a good OS-Developing language?

Programming, for all ages and all languages.
DJAlexem
Member
Member
Posts: 33
Joined: Wed Sep 07, 2011 7:57 pm
Location: NSW, Australia

Is C a good OS-Developing language?

Post by DJAlexem »

Hey guys, I'm new here, this post is probably a load of crap to most of you, but anyway:

I know C is a low level language, i am currently learning some of it, but is it a very good language for making things like kernels and Operating Systems? I understand most of this prograaming language stuff, when it comes to theory I pick it up quickly, but when it comes to actually writing code, I don't perform as well. but none-the-less...

I notice you guys use Assembly and machine code a fair bit in making these OSs, Do you use that with other low level programming languages?

And Qemu, is that like a simulator? I'm just curious cause making my own OS or programming language is something that I wanna get done in my life(im 15 atm btw :D)...

I am kinda noob, and ive been watching this site for a pretty long time lol.

Thanks to anyone who can help me understand some of these questions.

BTW, this site is so fking awesome....just thought i'd put that out there :D
Just a n00b C programmer, aiming to enter the world of advanced programming through OSDev :D

My Mixes
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Is C a good OS-Developing language?

Post by Brendan »

Hi,
DJAlexem wrote:I know C is a low level language, i am currently learning some of it, but is it a very good language for making things like kernels and Operating Systems?
C is probably the best language for things like kernels: lots of people are familiar with C, there's lots of example code in C (including Linux, FreeBSD, etc), there's several good free C compilers (that you could port to your own OS one day), it's low-level enough to do almost everything and it's high-level enough that you don't end up spending all day twiddling bits.

For all languages (except assembly), there's a few special instructions that a kernel needs to use that no higher-level language supports. This means that some assembly language is unavoidable. Assembly language is harder to get right and harder to maintain, so I wouldn't recommend using assembly language by itself (e.g. better to do everything you can in C, and only use assembly for the tiny pieces that no high level language can do).
DJAlexem wrote: I understand most of this prograaming language stuff, when it comes to theory I pick it up quickly, but when it comes to actually writing code, I don't perform as well. but none-the-less...
Learning the theory isn't too hard. Gaining experience takes practice. That's another good thing about C (and C++) - people can and do use it for writing applications; and you can get a lot of experience writing applications in C, where there's lots of debugging tools, etc to make it easier. This is probably important, because OSs are complex, and it would be much harder to write an OS when you don't have much experience with the languages you're using (much better to get experience writing applications for Linux or something; and then start your OS when you've got experience).
DJAlexem wrote:I notice you guys use Assembly and machine code a fair bit in making these OSs, Do you use that with other low level programming languages?
Most people use C (with a little bit of assembly) for kernels. Some people use C++ (with a little bit of assembly), some use assembly alone. A few rare people use other languages (Pascal, C#, D, something they invented themselves, etc).
DJAlexem wrote:And Qemu, is that like a simulator? I'm just curious cause making my own OS or programming language is something that I wanna get done in my life(im 15 atm btw :D)...
Qemu is a virtual machine - a normal application that emulates a computer, that people use for testing their OSs to avoid rebooting a real computer a lot (it saves time). It also means if you mess something up you don't have to worry about trashing your (real) hard drive. The other reason to use virtual machines is that it's easy to have bugs that work on some computers and fail on other computers; so to increase the chance of finding those bugs you want to test on lots and lots of different computers. Virtual machines (Qemu, Bochs, VirtualBox, VirtualPC, VMware, etc) are a cheap way of increasing the number of "computers" you can test on (and increasing your chances of finding bugs).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
DJAlexem
Member
Member
Posts: 33
Joined: Wed Sep 07, 2011 7:57 pm
Location: NSW, Australia

Re: Is C a good OS-Developing language?

Post by DJAlexem »

wow, thx for the very indepth answer Brendan :D

This is extremely helpful, and amazingly understandable.... xD

So it looks like ill be sticking to C, I like it too....unlike a lot of those higher level languages, lol.

once again, thank you brendan for the time and effort! :)

Anyone else got any tips or answers to help me with C?
Just a n00b C programmer, aiming to enter the world of advanced programming through OSDev :D

My Mixes
cxzuk
Member
Member
Posts: 164
Joined: Mon Dec 21, 2009 6:03 pm

Re: Is C a good OS-Developing language?

Post by cxzuk »

Id actually recommend learning how ASM works, because C is very closely related. It'll help you understand some computing principles.

mike brown
DJAlexem
Member
Member
Posts: 33
Joined: Wed Sep 07, 2011 7:57 pm
Location: NSW, Australia

Re: Is C a good OS-Developing language?

Post by DJAlexem »

LOL, ASM is my initials

Alexander
S*m*e*
M*P*e*s*n

yeh, i blank my own name >.>

anyway, ill look into it tomoz, thanks Mike!

EDIT: holy crap assembly is complicated... its just memory and extremely low lvl handling O_O
Just a n00b C programmer, aiming to enter the world of advanced programming through OSDev :D

My Mixes
chibicitiberiu
Member
Member
Posts: 68
Joined: Thu May 28, 2009 11:46 pm

Re: Is C a good OS-Developing language?

Post by chibicitiberiu »

C was initially made for developing the Unix kernel... so yeah, C is one of the best languages for writing kernels.

Assembly is more complicated, and less portable... but it's very important to know when writing a kernel...
Debugging is a nightmare without knowing assembly, and some things you cannot do without it.
Tibi,
Currently working on the Lux Operating System
User avatar
xvedejas
Member
Member
Posts: 168
Joined: Thu Jun 04, 2009 5:01 pm

Re: Is C a good OS-Developing language?

Post by xvedejas »

Alexander
S*m*e*
M*P*e*s*n
Alexander Samuel McPherson?
Assembly is more complicated, and less portable... but it's very important to know when writing a kernel...
Exactly, I think that to be able to write a kernel well, you should code in C but often think in assembly. C is just high level enough to be useful and portable, but low level enough to not forget what's really happening behind the scenes. So far as I'm concerned, it's the goldilocks spot of low-level programming.
DJAlexem
Member
Member
Posts: 33
Joined: Wed Sep 07, 2011 7:57 pm
Location: NSW, Australia

Re: Is C a good OS-Developing language?

Post by DJAlexem »

LOL, thats a cookie for xvedejas! you guessed my name!

so you can do most of the stuff you can do in assembly by using C alone? is it THAT low level?

plus, does anyone know where i can find very good online C tutorials, the one i wa currently following only had 14 episodes, so now im stuck xD

I mean a very very good tut...

thx again guys, this is really opening my eyes...
Just a n00b C programmer, aiming to enter the world of advanced programming through OSDev :D

My Mixes
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: Is C a good OS-Developing language?

Post by Brynet-Inc »

DJAlexem wrote:LOL, thats a cookie for xvedejas! you guessed my name!
No, you're the king of obfuscation and he's just a clever savant.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Is C a good OS-Developing language?

Post by AJ »

Hi,
DJAlexem wrote:EDIT: holy crap assembly is complicated... its just memory and extremely low lvl handling O_O
Although it looks it to start with, Assembly isn't actually that complicated. It may be more difficult to write maintainable code, but each line of assembly code actually does something extremely simple. It's all a matter of what you are familiar with. Have a look at OS Dever. There are a couple of really simple floppy bootloader examples on there (starting with a jmp $ infinite loop) that I think are an excellent way to get the gist of how it works.

As chibicitiberiu says, you will need assembly for debugging, particularly as that's what the emulators output when showing you the current instruction at eip...

I've provided this link before and I'll provide it again - if you are going to practice any assembly hand-coding, this article is excellent: http://www.swansontec.com/sregisters.html.

Cheers,
Adam
DJAlexem
Member
Member
Posts: 33
Joined: Wed Sep 07, 2011 7:57 pm
Location: NSW, Australia

Re: Is C a good OS-Developing language?

Post by DJAlexem »

hmm, these are really good, thank you adam :D

But i come across another problem D: ...

I can't find a windows version of qemu, just linux ones, i also cant find a way of compiling C files into O files, eg:

kernel.c --> kernel.o

I got a compiler for .asm to .o, so no worries there.

But i need to find a good emulator, just a simple one, that works for windows, I fail at trying to find one.... I also has virtualbox, but it wasnt what i thought it would be xD

so checklist:

-> .c to .o compiler
-> virtual machine emulator for windows that is easy to use

Thx again guys!

and thx again adam for the assembly tutorials!

-Alexem
Just a n00b C programmer, aiming to enter the world of advanced programming through OSDev :D

My Mixes
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Is C a good OS-Developing language?

Post by AJ »

Hi

Google is your friend. But don't rely on one emulator. Also use Bochs and some virtual machines like VPC, Virtualbox and not forgetting real hardware tests too!

Cheers,
Adam
DJAlexem
Member
Member
Posts: 33
Joined: Wed Sep 07, 2011 7:57 pm
Location: NSW, Australia

Re: Is C a good OS-Developing language?

Post by DJAlexem »

AJ wrote:not forgetting real hardware tests too!
LOL, dad would kill me if i tried to boot my own operating system onto the PC... -.-'

OK, ill try bochs, and the GCC thing, im was just having trouble finding a working windows one compatible with vista...

thx!
Just a n00b C programmer, aiming to enter the world of advanced programming through OSDev :D

My Mixes
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Is C a good OS-Developing language?

Post by VolTeK »

Brynet-Inc wrote:No, you're the king of obfuscation and he's just a clever savant.
Image
I had a feeling..
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Is C a good OS-Developing language?

Post by AJ »

Hi,
DJAlexem wrote:OK, ill try bochs, and the GCC thing, im was just having trouble finding a working windows one compatible with vista...
I use Bochs, Qemu, VPC and VirtualBox. All of which ran on my old Vista machine and still run on my Windows 7 machine (when I get time to use them...). As far as the "GCC thing", both the Windows operating systems I regularly use happily run Cygwin with GCC Cross Compilers.

Cheers,
Adam
Post Reply