Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ Programming ➜ General ➜ [ROM] C to C++

[ROM] C to C++

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Rapture   USA  (13 posts)  Bio
Date Fri 03 Sep 2010 04:52 AM (UTC)
Message
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.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #1 on Fri 03 Sep 2010 05:06 AM (UTC)
Message
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.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Rapture   USA  (13 posts)  Bio
Date Reply #2 on Fri 03 Sep 2010 03:31 PM (UTC)
Message
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.
Top

Posted by Samson   USA  (683 posts)  Bio
Date Reply #3 on Fri 03 Sep 2010 06:04 PM (UTC)
Message
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 :)
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


15,893 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.