Thread: Ability to use C++ to program an OS

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    2

    Question Ability to use C++ to program an OS

    Im currently in the planning stages of an operating system I'm designing. Is it possible to write the kernel, filesystem, and basically everything except the bootcode in C++ or do I have to use C? Also someone suggested using assembly to write the kernel, what are the downfalls of using C/C++? And what compiler should I use that would let me do what I need it to do easily. Im downloading bloodshed devcpp right now, and possibly looking at MSVC6 professional. Thanks in advance.

  2. #2
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    I'd use GCC for portability. There are bootloaders available if you don't want to write your own. I would think most of the OS would be done in C (non-object code). Some parts might be good to do with C++ (object code) but it's not necessary.
    If you're going to make a Windows like OS then by all means use VC++.
    I've thought about making an OS but it's a long-term project and I doubt I'm the next Bill or Linus. I've decided to dig into the Linux OS and help contribute to that cause instead. I think it's a little more practical.
    Good luck to you though.

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    You can use c++ for writing most of the kernel although c or even better asmwould be much faster. If you use c/c++ be aware that you will needto write your own c library. Also using malloc,new and delete will cause problems until after you have written your memory manager and interfaces.
    For compilers.... neither devc or msvc will be suitable.Both are windows compilers. You will need something like gcc to write an os.You will also need NASM. Its probably the best assembler.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    although in theory assembler would be ideal for the kernel, providing the access to the low level system, your high level language will be converted and optomized far better than a programmer can acheive.

    and i dont know about you but i wouldnt like to write an os kernel in assembler!
    Monday - what a way to spend a seventh of your life

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    2
    Well I'm about to start learning C++ to program the OS to avoid having someone else do it. The OS will have a nice GUI and stuff like Windows. If I learn C++ and decide to program most of the OS in C, will my knowledge of C++'s functions mess me up in C? Will I have to learn C by itself?

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    I would say conservative estimate that to write an operating system you will need a minimum of 5 years experience of c/c++ and be fluent in both real mode and protected mode asm. Writing an operating system is a major task. It is probably the most difficult piece of programming that you will ever attempt. Put your plans off until you know at least c/c++ and 16 bit/32bit asm. It is pointless to even think about writing an os if you have not yet learnt the languages and had some time using them to solve problems. Think instead about just learning the languages. By all means read a book or two about os design and you will immediately see that you are way over your head.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Really dude. If you don't know C++, then why try to program one of the hardest things you can program?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM