DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2005

    How to convert a C code into C++

    Hi friends,

    I need to convert a big C project into C++.
    Can anyone tell me how to do this?
    What are the steps must be taken to do this?
    or is there any tool to do this?

    or any nice articles abt this?

    Thanx in advance.

  2. #2
    Join Date
    Dec 2003
    It depends on what you mean. If you want to make a C project object oriented, you will have to do it by hand with a redesign of the code (unless its a rare, struct and function pointer OO C project-- very few are like this!). I recommend understand C (you can download a trial version) if you do not know what the code does and how it does it. If you just want to compile it, a c++ compiler can already compile C files. If you want to change the extensions to .cpp, you don't have to do much, just fix the malloc's and a couple of other small things (the compiler will tell you). Normally, unless you plan to do a major overhaul that is about the same as starting over, OO-ing it is not a good path to go down.

  3. #3
    Join Date
    Apr 2005
    Thanx a lot for ur suggestions.

  4. #4
    Join Date
    Nov 2003
    First off, try to compile it as a C++ project (you'd probably need to change the file extensions) and see which compilation errors you're getting. Then fix these errors. Depending on the C subset you're using, these errors can be minimal or a torrent of corrections. For example. if your functions don't have prototypes, then you will have to fix that. Similarly, if your code uses void * all over the place you will need to add explicit casting operators etc.
    Don't rush to make it object-oriented. If it works correctly and satisfactorily, leave it as is so long as the code complies with ISO C++. Refactoring it to OO requires a serious design and recoding processes; it's not just throwing a bunch of classes into what used to be C code. This is in fact a mistake that many people do when they migrate from C to C++.
    Danny Kalev

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.