Page 1 of 5
Is C a good OS-Developing language?
Posted: Wed Sep 07, 2011 8:18 pm
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
)...
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
Re: Is C a good OS-Developing language?
Posted: Wed Sep 07, 2011 9:07 pm
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
)...
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
Re: Is C a good OS-Developing language?
Posted: Thu Sep 08, 2011 2:05 am
by DJAlexem
wow, thx for the very indepth answer Brendan
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?
Re: Is C a good OS-Developing language?
Posted: Thu Sep 08, 2011 3:50 am
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
Re: Is C a good OS-Developing language?
Posted: Thu Sep 08, 2011 5:37 am
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
Re: Is C a good OS-Developing language?
Posted: Thu Sep 08, 2011 7:40 am
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.
Re: Is C a good OS-Developing language?
Posted: Thu Sep 08, 2011 11:12 am
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.
Re: Is C a good OS-Developing language?
Posted: Fri Sep 09, 2011 6:15 am
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...
Re: Is C a good OS-Developing language?
Posted: Fri Sep 09, 2011 9:42 am
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.
Re: Is C a good OS-Developing language?
Posted: Fri Sep 09, 2011 12:46 pm
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
Re: Is C a good OS-Developing language?
Posted: Sat Sep 10, 2011 3:49 am
by DJAlexem
hmm, these are really good, thank you adam
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
Re: Is C a good OS-Developing language?
Posted: Sat Sep 10, 2011 11:00 am
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
Re: Is C a good OS-Developing language?
Posted: Sat Sep 10, 2011 8:40 pm
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!
Re: Is C a good OS-Developing language?
Posted: Sat Sep 10, 2011 10:30 pm
by VolTeK
Brynet-Inc wrote:No, you're the king of obfuscation and he's just a clever savant.
I had a feeling..
Re: Is C a good OS-Developing language?
Posted: Sun Sep 11, 2011 12:53 pm
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