locked
Why .Net languages cannot be compiled to machine code? RRS feed

  • Question

  • 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

    Tuesday, September 19, 2006 6:24 AM

Answers

  • 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.
    Tuesday, September 19, 2006 8:36 AM

All replies

  • 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.
    Tuesday, September 19, 2006 7:51 AM
  • 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.
    Tuesday, September 19, 2006 8:36 AM