C# to C++ conversion?

This is a discussion on C# to C++ conversion? within the C# Programming forums, part of the General Programming Boards category; Hi! I am wondering if there exist any good tool for conversion from C# to C++? ~Elena...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    7

    C# to C++ conversion?

    Hi!
    I am wondering if there exist any good tool for conversion from C# to C++?
    ~Elena

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,205
    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.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    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.

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,487
    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.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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.

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    7
    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.

  6. #6
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    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.

  7. #7
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,487
    Quote Originally Posted by hammari View Post
    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.
    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.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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.

  8. #8
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    We are developing a new embedded system using tools that only support C/C++ for the moment
    .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.

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Quote Originally Posted by VirtualAce View Post
    .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.
    Yes but .NET at least tripled my XPe size (from ~80Mb to over 300Mb), which is expensive when using industrial grade SD or ruggedised HDs and the garbage collector was not really good/quick enough on a system using the EWF.
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 10:31 PM
  4. Do I have a scanf problem?
    By AQWst in forum C Programming
    Replies: 2
    Last Post: 11-26-2004, 05:18 PM
  5. Creation of Menu problem
    By AQWst in forum C Programming
    Replies: 8
    Last Post: 11-24-2004, 08:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21