If one were brave enough to attempt a port from C to C++, what would be some of the obstacles in doing so?
I figure there are loads of benefits in attempting this, but I'm not overly familiar with the language. This would be a learning experience for me.
The major issues you will run into...
- If you have constructors, you need to initialize the objects in question with 'new', not just malloc. Anything you create with 'new' must be destroyed with 'delete', not just free.
- g++ tends to be stricter than gcc; you will have to fix a lot of warnings like string constness.
If you don't have a clear idea of the benefits, then to be honest I wouldn't bother until you do. (There are benefits, it's just that you need to know how to take advantage of them to get them.) And when you do decide to convert, you really don't want to convert everything at once. You can convert in pieces, since C++ is (barring a few exceptions) basically a superset of C. (You'll have issues like 'class' no longer being an acceptable variable name.) So, convert pieces as you find ways to take advantage of C++. There is relatively little benefit in spending lots of time converting something if you only get gains in 5% of it; just convert the part you'll gain from. Many a coder has gotten burned out trying to convert everything in one fell swoop; it's easy to introduce bugs as you rearrange how memory is managed.
Thank you for the advice. Like I said, it's more of a learning experience than an optimization.
I'll look into it a bit more.
Yes, take it from one who burned himself out on it. Don't go nuts and try to transform your entire codebase all at once :)