C++ to C# Converters?

Recommended Posts

Davaris1    151
Hi, I was wondering if anyone can tell me if these products are of any use and which are the market leaders. I have a pretty big C++ project that I want to convert to C#, so doing it by hand is out of the question.

Share on other sites
Decrius    100
I don't see why you want to convert a working project, to another language. You'd only create bugs, and the machine really doesn't mind what language it was written in!

Why not just build a C#-bind for the C++ code? Some C# wrapper, if the functions are inlined, there's no performance hit at all.

Share on other sites
CodeMunkie    805
Why do you want to do this?

Share on other sites
Zahlman    1682
Presumably in order to be able to hire c# developers to continue the development instead of c++ developers. :/

Share on other sites
Nypyren    12063
You'll have to do it by hand. Automated software to do this would have to be almost as smart as a programmer, or customized specifically for your project.

There are too many things you can do in C++ that you have to totally redesign for C#. (unions, multiple inheritance, advanced templates, inline assembly, arbitrary pointer manipulation)

Have you considered rewriting it section by section? C# can interoperate with C++ really nicely in a lot of projects. You can migrate stuff you want to update to C# as you need them.

[Edited by - Nypyren on March 9, 2010 4:11:27 PM]

Share on other sites
Davaris1    151
Why am I doing it? I am converting my old 2D C++ Game to use the Unity3D engine and can't afford the Pro license at \$1500. :) Also I find C++ is too much work and don't enjoy coding in it anymore. My favorite language is Python because it is so simple and clean, but Unity3D only support a bastardized version of Python called Boo and TBH, I am not sure how different it is to standard Python. Actually I hadn't considered a Python converter before now...

Share on other sites
Nitage    1107
One option is to compile your C++ as C++CLI. Then you can use C# for new work, and (fairly) easily integrate it with the older code.

Quote:
 Unity3D only support a bastardized version of Python called Boo

Boo's a language that has Python-like syntax, it's not a version of Python. Rather like how ECMAScript and C look similar at a glance.

Share on other sites
daviangel    604
Quote:
 Original post by DecriusI don't see why you want to convert a working project, to another language. You'd only create bugs, and the machine really doesn't mind what language it was written in!Why not just build a C#-bind for the C++ code? Some C# wrapper, if the functions are inlined, there's no performance hit at all.

Agreed. I've used VB to C# converters before and even though they are a lot more similar to each other than C++ and C# it didn't work too good.
You'll spend just as much time finding all the subtle errors introduced by a conversion program most likely.

Share on other sites
phresnel    953
Quote:
 Original post by NypyrenYou'll have to do it by hand. Automated software to do this would have to be almost as smart as a programmer, or customized specifically for your project.There are too many things you can do in C++ that you have to totally redesign for C#. (unions, multiple inheritance, advanced templates, inline assembly, arbitrary pointer manipulation)

Just wanted to add that even the simplest templates like tuples are already forbidden in C#, or more generally, every single templates that uses non-type parameters, and every single partial or full specialization.

And then, not even type template argument powered templates are hard to replace when you consider lazy instantiation of C++ templates versus eager 'instantiation' of C# generics; e.g. where in C++ something like ...

template <typename T> struct Foo {    T some_var;    void frob() {        frob(some_var);    }};

... is allowed even when instantiating Foo upon a T for which no frob(T) is defined, which is not trivial to solve for in C# (the most trivial workaround would be to define a "frob(object)" (which is a bit like a "frob(void*)"), which in turn would call the right frob upon RTTIing its parameter.

--

And to add some more, it is hard, up to impossible, to replace some other things like destructors, friend declarations, type aliases.

Finally, of course every problem can be translated into any other (computationally complete) programming language, but in many cases you end up with largely non-reusable, one-way-road code (e.g. you could replace tuples<> by simple structs/classes, and lose the concepts of tuples entirely (and have I already mentioned how you would have to introduce a ton of Disposable objects, using statements, and there were using statements are not an option, you most probably would have to add Disposable interfaces upon containing classes, just to be sure)...

All that, yes, hand transcribe it, or hook to it like Nitage describes.

Create an account

Register a new account