Why .Net languages cannot be compiled to machine code?

Does anyone know of a logical reason why any .net language cannot be compiled down to machine code except for c++.Net

In the end the compiler has to make calls to machine level functions anyways, so wy can it not include those and just copile down to exe machine code form

Just curious, since c++.Net can do it either way, I could not find a reason why they could not make c# or any other language do the same thing.

Thanks,

Chad




Answer this question

Why .Net languages cannot be compiled to machine code?

  • R.Working

    Of course they can be compiled, the CIL code would not be run othervise. Check if this helps you: http://msdn2.microsoft.com/en-us/library/6t9t5wcf.aspx

    But the WHOLE idea of the CIL language is that the code IS NOT compiled to the native language, so the code can be run on every processor.

  • vcboy

    That's right - the .NET languages are JIT-compiled at runtime, but Microsoft has provided you with a native compiler too!
    If you want a .net assembly (which contains CIL language, ready to be JIT compiled at runtime) compiled to native code, you can use ngen.exe.

    You will lose many benefits that the JIT compiler would give though, and performance increase is not always noticable. Infact, you might even have a slight performance decrease, depending on what your code does.


  • Why .Net languages cannot be compiled to machine code?