[Home] [Downloads] [Search] [Help/forum]

Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  Programming
. -> [Folder]  General
. . -> [Subject]  [ROM] C to C++

[ROM] C to C++

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

Posted by Rapture   USA  (13 posts)  [Biography] bio
Date Fri 03 Sep 2010 04:52 AM (UTC)
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.
[Go to top] top

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

[Go to top] top

Posted by Rapture   USA  (13 posts)  [Biography] bio
Date Reply #2 on Fri 03 Sep 2010 03:31 PM (UTC)
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.
[Go to top] top

Posted by Samson   USA  (683 posts)  [Biography] bio
Date Reply #3 on Fri 03 Sep 2010 06:04 PM (UTC)
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 :)
[Go to top] 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.


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

Go to topic:           Search the forum

[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]