Bona Fide OS Development
http://forums.osdever.net/

C or C++
http://forums.osdever.net/viewtopic.php?f=5&t=51
Page 1 of 1

Author:  Kieran [ Sun Oct 18, 2009 11:11 am ]
Post subject:  C or C++

Guys, I have only tried OSDev in C, I did put a token effort into C++ once, a long time ago, but I didnt get anywhere. Could anyone please list any pro's/con's of C++ over C. Im thinking of recoding my OS to support more, but I think I should choose my language better this time and I know C++ has object capabilities, but I also know theese need added library code too.

Author:  Michael [ Sun Oct 18, 2009 11:14 am ]
Post subject:  Re: C or C++

Well, personally I use C, but I have coded an OS in C++ before. I do believe it would be possible to mix both languages - you would need to use different compilers, and link the seperate object files, of course. However, remember that when it comes to OS Dev, C++ is a completely different language. Take a look here.

Author:  ctimko [ Sun Oct 18, 2009 12:16 pm ]
Post subject:  Re: C or C++

With C++ you just need extra support in your code. Just remember that when you are doing your New and Delete operators, that you will also need to have the Constructors and Destructors in there, despite what some tutorials say, this is the proper way of using it. Delete, and _atexit are the only things that should be calling your destructor, you shouldn't call it manually unless you want to be a person who doesn't dealloc space.
((for now I would just go with the who free'ing, and when i figure out how to tap the .ctors and .dtors properly, then I will post how to do the new and delete properly)).

~Charles

Author:  Kieran [ Mon Oct 19, 2009 7:35 am ]
Post subject:  Re: C or C++

Ah, now I underatand one of your other posts Charles. I understand what you are saying, but what about any objects created at runtime without the New keyword, maybe this doesnt happen and is just in my head, but it is there :P

Author:  Love4Boobies [ Mon Oct 19, 2009 8:44 am ]
Post subject:  Re: C or C++

There's not much extra work if you want to use C++ instead of C. I find that the benefits are worth it. Check out this article to see exactly what you need to support (note that it was written around GCC but most of it will apply for any compiler). I also wanted to mention that although there's no direct language support for OOP in C, it can be done.

Pros for using C++ instead of C:
  • You get all the nice C++ features such as OOP, generic programming and such.
  • Your OS will probably end up having less bugs because you're using a higher level of abstraction (e.g., the new and delete operators).

Cons:
  • You'll probably find less help in the community because not as many people use C++ as C. Lately this con has been fading out as I've seen more and more people aiming for C++. You'll also find less examples out there (almost none for more advanced stuff).
  • You need to code in a bit more support.

This list isn't as big as you might have expected, right? :) In the end just use whatever you're most comfortable with.

Cheers,
Bogdan

Author:  Arlen [ Sat Jan 16, 2010 8:31 pm ]
Post subject:  Re: C or C++

Michael wrote:
Well, personally I use C, but I have coded an OS in C++ before. I do believe it would be possible to mix both languages - you would need to use different compilers, and link the seperate object files, of course.


This isn't quite the case - you could do your entire system in pure C but still use a C++ compiler. The output will be the same - so it doesn't complicate your build environment as much as you might expect at first.

You'll need to link separate object files just the same way you link two object files produced from two C source files - they're not incompatible or anything like that.

:)

Page 1 of 1 All times are UTC - 6 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/