tl;dr: Why would I ever choose to write/compile unmanaged1 code?
Lets assume that I am starting a new project. I have decided to write in a C-like language - probably one of C, C++, C# or Java. C# and Java are managed (well, Java runs in the JVM, but lets assume that it is same thing). Managed GCC plugins exist (although I have not used any, so I do not know if they are any good). Managed code has lots of advantages:
- You do not have to worry about explicitly garbage collecting (which is fiddly)
- It is much harder to memory leak
- It is trivial to implement - just choose the correct language or right compiler flags
- e.g. use C#, or use MCP for GCC
- Improved interoperability if you are compiling into IL
- Type safety, array bound and index checking etc
In my opinion (which could be wrong - and I am trying to ascertain why it is wrong) it is better almost always to used managed code. However unmanaged languages exist and managed languages have unmanaged flags, so there must be some reasons for choosing it over managed code. What are the reasons?
Edit: As Deduplicator points out it is possible to use a GC in non-managed code (either third party or one you create yourself). This leads to another related question: Does everybody compiling native C/C++ code use a GC? If not, what are the advantages for not using a GC?
1. For the purpose of this question I am borrowing John Bode's definition of "Managed" (below) - anything that runs in a virtual machine, not just the Microsoft definition of managed code. I count Java as a "managed" language in that it runs in a VM.