Bona Fide OS Developer
View unanswered posts | View active topics It is currently Thu Mar 28, 2024 5:46 pm



Post new topic Reply to topic  [ 6 posts ] 
 C or C++ 
Author Message
Site Admin

Joined: Sat Jul 25, 2009 7:44 am
Posts: 274
Location: United Kingdom
Post 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.

_________________
Thank you for reading,

Kieran C G Foot


Sun Oct 18, 2009 11:11 am
Profile WWW

Joined: Sat Jul 25, 2009 6:10 am
Posts: 112
Location: United Kingdom
Post 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.

_________________
Thanks,
Michael Sammels

OS Developing is 10% luck, 20% skill, 15% concentrated power of will. 5% pleasure, 50% pain, and a 100% reason continue the game.


Sun Oct 18, 2009 11:14 am
Profile

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post 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

_________________
Charles Timko
push %esp ;Musings of a computer addict


Sun Oct 18, 2009 12:16 pm
Profile WWW
Site Admin

Joined: Sat Jul 25, 2009 7:44 am
Posts: 274
Location: United Kingdom
Post 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

_________________
Thank you for reading,

Kieran C G Foot


Mon Oct 19, 2009 7:35 am
Profile WWW

Joined: Sat Jul 25, 2009 11:26 am
Posts: 81
Post 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


Mon Oct 19, 2009 8:44 am
Profile

Joined: Sat Jan 16, 2010 7:53 pm
Posts: 18
Location: Melbourne, Australia
Post 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.

:)


Sat Jan 16, 2010 8:31 pm
Profile WWW
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 


Who is online

Users browsing this forum: No registered users and 26 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin and tweaked by the BF Team.