Sign in to follow this  
Davaris1

C++ to C# Converters?

Recommended Posts

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 this post


Link to post
Share on other sites
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 this post


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

Share this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
Quote:
Original post by Decrius
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.

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 this post


Link to post
Share on other sites
Quote:
Original post by Nypyren
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)


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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this