Page 1 of 2

Should my Kernel be written in C or C++?

Posted: Sat Mar 27, 2004 12:00 am
by Freakyprogrammer
ok, I have been studying OSdev for a while now and I am going to start writtng my kernel soon, and I was wondering which language i should use... C or C++, I have read that it would be better to do it in C because some of the things that C++ relies on, I would have to write myself... but can someone please clear this up? thanks

               peace out
                  - Freakyprogrammer

RE:Should my Kernel be written in C or C++?

Posted: Sat Mar 27, 2004 12:00 am
by ASHLEY4
I would make it with ASM, if i liked C i would not need to make a OS, i would use Linux. The fact that there is no os for ASM programmers is the reason i am making my os.
Menuet is a good OS,But i already started mine, when i found out about Menuet.

Iv started so ill finish!:-)

ASHLEY4.

RE:Should my Kernel be written in C or C++?

Posted: Mon Mar 29, 2004 12:00 am
by Anton
// The fact that there is no os for ASM programmers
Why? I can write in asm in any OS.
I like C(& C++), but i don't like Linux, since i don't like it's philosophy. So that is why i whant to write an OS.
Anton.

RE:Should my Kernel be written in C or C++?

Posted: Mon Mar 29, 2004 12:00 am
by Anton
You can write in C++(and you should). And don't worry about " some of the things that C++ relies on". C++ was writen as a langages for OS programming, not for application programming as it is used now. You wont have any problems at all, if you wont make them yourself. Like don't use runtime class stuff, ...C does not have it, so why would you use it in C++?
Anton.

RE:Should my Kernel be written in C or C++?

Posted: Mon Mar 29, 2004 12:00 am
by jcmatias
C is very simple and reliable. But OOP is the fashion today, and, belive me simplify too much a development in all levels.
As Anton says that C++ have a lot of things that requeries atention. You must create ( its valid to C too) create your all script to compile/link your OS. I recomend GCC - is the best - You can use DJGPP or CYGWIN in dos/win.(A lot of people says that C/C++(gcc) cant handle Interruptions - its false - I do it very well). The chalenger its to build a os with a verys small ( but inevitable) use of assembler - I sugest that you put your assembler (machine dependent code) in a specifc and isolated place of code - that can be interchageable -

RE:Should my Kernel be written in C or C++? - Mix IT Up

Posted: Mon Mar 29, 2004 12:00 am
by TheUbu
Freakyprogrammer,

You can actually mix it up and use both in your kernel. There are some things which may require use of an object oriented programming language. Some of these things would be scheduler using more modern techniques or a message passing interface. I use a mixture of within my kernel however make sure you have some of the basics from libs done such as new new[] delete delete[] its all part of the STL which will  be required when you start to compile your own kernel.


-Christopher

RE:Should my Kernel be written in C or C++?

Posted: Mon Mar 29, 2004 12:00 am
by ASHLEY4
Anton: have ever try geting the int 80h numbers for linux to use in asm, They want you to use the C library's.
Your wright on one thing, There philosophy stinks.

ASHLEY4.

RE:Should my Kernel be written in C or C++?

Posted: Tue Mar 30, 2004 12:00 am
by common
I have, works great.  Extremely efficient.

RE:Should my Kernel be written in C or C++? - Mix IT Up

Posted: Tue Mar 30, 2004 12:00 am
by Freakyprogrammer
Thanx Everyone for the help...


         peace out...
               - Freakyprogrammer

RE:Should my Kernel be written in C or C++?

Posted: Wed Mar 31, 2004 12:00 am
by Anton
>There philosophy stinks
How do you picture the philosophy of an OS, which has asm as it's native language?
Anton.

RE:Should my Kernel be written in C or C++?

Posted: Sat May 01, 2004 11:00 pm
by ezanahka
>How do you picture the philosophy of an OS, which has asm as it's native >language?
>Anton.

Extreme control and flexibility.

- Esa

RE:Should my Kernel be written in C or C++?

Posted: Sat May 01, 2004 11:00 pm
by ezanahka
"C++ is a general purpose programming language with a bias towards systems programming"

Avoiding runtime stuff like virtuals isn't the problem. The problem is that with high-level languages the compiler can rape your code by hiding inefficiencies behind abstractions if you are not very careful... And saying that you shouldn't use a feature because C doesn't have it simply doesn't cut as an argument...

- Esa

RE:Should my Kernel be written in C or C++?

Posted: Tue May 04, 2004 11:00 pm
by Anton
>Extreme control and flexibility.
I can say the same thing about C or C++(and probobly thats what everyone whants, even if you ask bill gates, he will tell you that his os is flexibel and has extreme control:)), so could you be more specific:
how would you write a "hello world" program?
Anton

RE:Should my Kernel be written in C or C++?

Posted: Tue May 04, 2004 11:00 pm
by ezanahka
> > Extreme control and flexibility.
>
> I can say the same thing about C or C++

Assembler is at the lowest possible level of abstraction because it does no hw abstraction while C and C++ are usually referred to as high-level languages because they are in themselves abstractions. With C and C++ your control of the machine is not as comprehensive as with assembler exactly because you are working at a higher level of abstraction. C and C++ do not give you absolute control of every single detail and therefore they also do not give you explicit control over those details.

How do you easily and explicitly control the processor's registers with C or C++? How do you use machine instructions meant for system programmers from C or C++? By writing a procedure in assembly language or using inline assembly but that is no longer C or C++.

> (and probobly thats what everyone whants, even if you ask bill gates, he will
> tell you that his os is flexibel and has extreme control:)), so could you be
> more specific:

Windows, Linux and other OSes are not assembly friendly systems as they contain an extremely high-level HAL (hardware abstraction layer). Sure you can use assembly in those systems for some thing but those systems themselves are not written with assembly programmers in mind because every useful thing you are allowed to do in those systems is more easily done with high-level languages. Exokernel and/or customisable OSes would probably be a little better but still too high level.

> how would you write a "hello world" program?
> Anton

In an assembly OS? By directly manipulating relevant hardware state without any extra abstraction/indirection/protection layers. Protection is necessary but that could be guaranteed without assembly programmer hindering abstractions or indirections. To me assembly OS doesn't mean that I must use assembler for doing everything on it. It simply means that I can do it if I want to for some reason. Since Win32 you've had to do everything through Win32 API and in Linux you have to use high-level kernel provided abstractions (POSIX) also instead of having direct but securely multiplexed access to relevant hardware.

- Esa

RE:Should my Kernel be written in C or C++?

Posted: Tue May 04, 2004 11:00 pm
by ezanahka
> > The fact that there is no os for ASM programmers
>
> Why? I can write in asm in any OS.
> I like C(& C++), but i don't like Linux, since i don't like it's philosophy.
> So that is why i whant to write an OS.
> Anton

Yes you can write asm in any OS, but you can't asm even nearly to it's full potential in every OS. To me assembly is also about doing exactly what you want the way you want to do it. In mainstream OSes the kernel prevents you from directly writing to and reading from hardware ports and physical memory directly past the virtual memory and paging mechanisms. How do you write a "Hello world!" in DOS compared to a Win32 or Linux? Asm put into the cage of an OS with kernel abstracting and protecting everything is like a lion with it's teeth and claws ripped out.

- Esa