Hi!
I am wondering if there exist any good tool for conversion from C# to C++?
~Elena
Hi!
I am wondering if there exist any good tool for conversion from C# to C++?
~Elena
I very much doubt you can just do a code translation. For one C# has a much bigger standard framework that can only be replicated in C++ in the form of third-party libraries.
Your best bet is to do a manual conversion really.
Why do you want to converte a program from C# to C++ anyway? Unless you have a very very specific reason I can't really see the benefit.
Why don't you just convert the C++ to C++ / CLI. The only major change is you have to change the pointer types to managed pointers (^), use gcnew instead of new (if needed), convert all the System.Blah.Blah to System::Blah::Blah, and bring in the .NET namespaces with using namespace declarations.
This would be a much simpler conversion and you would not have to convert all of the code. Actually you could just create a managed interface to your unmanaged code. That is even simpler and would take no time at all. If the C++ code base is well tested it does not make sense to port it over but it does make sense to give it a managed interface so it can be accessed from C# just as any other managed object.
There are code converters. But they don't work, of course. So that pretty much covers your question which was "I am wondering if there exist any good tool for conversion from C# to C++". No, there isn't.
Ideally what you want is to simply refer to your C# code from within C++ through a Managed C++ interface, just as VirtualAce describes. It's an elegant, powerful and sureshot solution for most of your integration problems. This short tutorial gets you started.
If you really want to port your C# code into C++, then you'll have to do it by hand.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
Thank you all! My problem is a specific one. We are developing a new embedded system using tools that only support C/C++ for the moment (research project). I have found a tool from Tangible Software Solutions Inc that claims to do the conversion from C# to C++, but it still needs a lot of manual postprocessing. This is of course an interesting task to learn C# better, but the time is very limited for our first experiment. I will look at the interface that you suggest.
I would try coming from the opposite direction. Can I use the C++ code in C#? There are two main methods of achieving this. First is P/Invoke. Second is using C++/CLI.
Yes, that's the problem with those tools. They only partially deal with the porting and on the other hand the generated code may not be what you expect and break many of your programming guidelines or habits. You'll feel forced to change also the generated code, which in the ends results in more work than simply porting by hand. If this is fine by you and you don't care about the C++ generated code (doesn't shock me at all, depending on the type of research you are doing), then they do make useful shortcuts indeed.
In any case, since you mention that your system doesn't support .Net development, don't bother looking at our proposed solution. It only makes sense if the system includes support for .Net since the assembly for which you create the interface isn't going anywhere. It will be required for C++ to be able to communicate with it.
Last edited by Mario F.; 03-14-2011 at 06:50 AM.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
.NET is supported on Windows XPE and Windows Embedded Standard if you are using those on your embedded system. Last I heard .NET 3.5 and 4.0 were awaiting official embedded 'certification' by Microsoft but it was expected these could be both used and supported in embedded environments within the next few months. .NET 3.5 may already have been certified.We are developing a new embedded system using tools that only support C/C++ for the moment
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill