Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I have a few .NET portable libraries written in C# which I need to port to Qt (C++). Since many of the classes don't really depend on .NET framework classes to a large extent, I thought it would be good strategy to use a tool to convert the C# code to Managed C++ first and then use that as the base for the porting it for use in Qt rather than rewriting the whole thing in C++
Are there any free tools to convert C# code or decompile a built assembly to Managed C++?
Since many of the classes don't really depend on .NET framework classes to a large extent, I thought it would be good strategy to use a tool to convert the C# code to Managed C++ first and then use that as the base for the porting it for use in Qt rather than rewriting the whole thing in C++
This is an error in reasoning. Managed C++ is not C++. Just because they're syntactically similar does not make the process of moving code across easier, on the contrary, you're making things unnecessarily harder for yourself.
The first thing that comes to mind is memory management. Your Managed C++ project will use GC object references (the ^ type) which cannot be easily converted to C++ memory-management semantics, nor is this something that can be done automatically unless you have your own Garbage Collection library you're prepared to weave into your existing program.
There is more to .NET than the framework classes, but consider the runtime environment. I've already touched on the GC, but what about Exceptions? Threading? The ABI? And so on.
You're better off rewriting it in pure idiomatic C++ rather than creating a mess that tries to straddle the CLR and pretend-C++.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I am writing a program that utilises a c# sdk. The functionality of this program will be used in a larger program written in c++ using QtCreator. I would like to create a c# dll to interact with the sdk and then consume this in the c++ program. Has anyone done this before and can point me in the right direction.
Many thanks.
You can, I do this regularly at work. You can consume C# from C++ using COM and Interop. Worth noting now that this is all windows only.
If you've not used COM from C++ before you are in for a nasty surprise. It's fairly unpleasant.
This is a very big topic, so I can't really cover it in a post, but if you want to learn more, I'd look here for starting on the C++ side:
COM(C++) programming tutorials?
I'd recommend using ATL to make your COM life a lot easier.
EDIT: Actually I didn't know this, but Qt has COM support, so you'd be much better off using that - Have a look at https://doc.qt.io/qt-5.10/activeqt-index.html
Google around for the C# side, but it's mostly about using the ComVisible and Guid attributes on your classes to make them COM ready and then registering them using regasm.exe (Part of the .NET Framework).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
For my diploma thesis I need to implement certain static C code analysis and I am desperately looking for a framework/library that would allow me to parse C source code, split it up into single functions, for every function determine what variables are changed in the function body and derive certain annotations for the code automatically.
Is there any good framework written in C# or generally as .Net class for this purpose?
What about googling for "C Parser written in C#"?
I got this as first link: http://code.google.com/p/cpp-ripper/
Also, I think the C grammar can be found in quite a lot of places, so you might just want to open up your .NET variant of lex/yacc and go from there?
You might like to check ANTLR. It comes with versions of several versions, included C and C#. There are some free grammars on ANTLR web site, including C.
I had a similiar problem and having done a research about YACC tools for C# I have chosen Gold Parsing System with Semantic Engine. My project was parsing SQL queries and generating logical query plans (from T-SQL grammar subset).
I really recommend it. Those 2 libraries make parsing stuff painless and allow to map grammar to the object model in your code. It feels very intuitive and made my project successful :) However, it may lack some advanced ANTLR features, so recognize your needs carefully.
Gold Project http://www.devincook.com/goldparser/
Semantic Engine Lib http://code.google.com/p/bsn-goldparser
If you're ok with using GPL'd code, you might want to take a look at the GCC source code. If you need to do it within .Net, you can always use p/invoke to call code from the GCC libraries.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm a C# programmer for a few months, and lately I've been considering learning C++.
So my question is, is there anything C++ can do that C# can't do?
I know about the manual memory management in C++, but as long as I don't program operating systems or extremely heavy memory applications, I shouldn't worry about that too much (becuase I heard .NET handles automatic memory management very well).
But, can I program in C# everything that I can in C#? I also mean things like DLL injection, Registry Editing, Drivers and things like that.
Is C# considered as powerful as C++? If not, what can't C# do that C++ can?
C# and C++ are languages. It's somewhat elusive to define what a language "can" and "can't" do. One example of a thing that C++ can do and C# can't, is free the memory of an heap allocated object at will, without freeing other unused objects as well. But it's a thing that won't matter most of the time. (You can use Marshal.AllocHGlobal and Marshal.FreeHGlobal to allocate and deallocate memory like in C.)
The main reason why C++ can be used to write things like Windows drivers is because this is what Windows supports and facilitates. If one day Microsoft decided to support only C# and ditch C++, we'd be here saying that C# can do something that C++ can't (even if the languages magically remained as they are now, by then). Most likely it won't, and rightly so, because C++ is better fit for systems programming than C#. But hopefully you get the point.
Essentially, it's not a matter of the languages themselves, but their implementations, their tools and the world around them. For example, you can easily write an operating system in C#. Why? Because there's a proper tool for it. You can also write for embedded systems with non-real-time requirements. It has nothing to do with the language, again, it's because there's a tool for it.
That being said, do learn C++. Regardless of how it compares with other languages, it's absolutely useful.
C# is a slightly higher level language that C++. Its requirement of a managed runtime environment means that you wont be able to write an operating system, or even a device driver, in it. This sort of area is typically known as systems programming
However, there is a Microsoft research project currently underway into creating a systems program version of C#. It's headed up by Joe Duffy, the Windows threading guru, and if the rumors on the web are to be believed it will be called M#. Joe has posted some information about his progress on his blog.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have been experimenting with OpenCL for quite a few days now, I'm using AMD's SDK and I'm now able to run a simple kernel in parallel and passing input/output to/from it.
I have to say though that I'm very disappointed by the lack of proper documentation for it, CUDA seems much more mature than OpenCL, but I cannot use CUDA because I don't have nVidia and because I want portable code.
I have read that AMD's OpenCL SDK now supports "static C++" extension which allows you to have some C++ features for writing the kernels, like inheritance and passing classes instances from the host to the device. However I cannot find ANY documentation for that or any examples.
To be short, my question is:
Where can I find documentation about using OpenCL's static C++ extension?
An extra question would be, where can I find PROPER documentation for the C++ wrapper (1.2 and not 1.1)
a super extra (:P) question would be, is there any complete/mature C# wrappers for OpenCL 1.2?? so far I found OpenCL.NET which is working fine, but again it doesn't have documentation so I have to look at the OpenCL C Reference and try to find the equivalent in C#
Thanks for reading this, I understand it's kind of ambiguous, all I want is an easy to use OpenCL SDK with proper documentation (Except C of course, I hate using plain C).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I know C# is different from .NET Framework, C# is a programming language that standard by ECMA (ECMA-334) and ISO (ISO/IEC 23270).
I don't want a converter that converts ANY C# source code (including .NET Framework) to C, but I want a tool that converts an ECMA standard C# source code to ANSI C source code.
Something like java2c but for ECMA C#.
There is not exactly such thing, but the Vala programming language is able to take a source code very similar to C#, and generate C codem or compile it directly.
http://live.gnome.org/Vala
Of course, the only problem are the libraries: C# has a lot of API's that you'll have to provide, or modify your source code to adapt to the Vala standard library.
If you wanted to translate this code to C because you need it compiled, there are other possibilities.
For example, ngen in the microsoft world:
http://msdn.microsoft.com/en-us/library/6t9t5wcf(v=vs.80).aspx
In the mono project, you can create a single exe file with the interpreter and the libraries. Look for mkbundle:
http://www.mono-project.com/Mono:Runtime
Mono is able to compile "ahead of time", i.e., generate the native code even before the program is going to be executed, so it will run faster.
http://www.mono-project.com/Mono:Runtime#Ahead-of-time_compilation
Depends on what you mean. If you mean "Is it possible to convert C# to readable and maintainable C-code?", then sorry, the answer is no — C# features don't directly map to C.