Click here to Skip to main content
15,886,091 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
We know in Dot Net Framework , Compiler compiles the managed Code to Intermediate Code and then to machine code.
 
Now my Question why Compiler straighforward compiles from Manage code to Machine Code. Why It has to first convert to Intermediate Language ? 


What I have tried:

Tried Googling but didnt find anything specific
Posted
Updated 20-Dec-18 5:40am
Comments
[no name] 20-Dec-18 11:43am    
As a non expert on this I see at least two things:
1.) Increase the chances to become more platform independed
2.) The "On the Fly" compilation of CIL (Common Intermediate Language) has the very big advantage, that it can be optimized on the current used cpu/architecture

There are two advantages. The compiler can convert different languages to the same CIL so multiple languages can leverage the framework, c# and vb.net being the best known. But anyone who wants to create a .net language only needs to know how to generate CIL.

The second advantage is that to run .net on a platform, that platform only needs the ability to convert CIL to it's own specific platform. So I can compile my c# app to CIL, then any CIL enabled environment can run that, so Windows using .net framework, or Linux using Mono, or anything else that understands CIL. If you went direct from c# to machine code then you would have to compile your program for a specific platform. With CIL you compile to CIL then the target platform worries about converting to machine-specific code.
 
Share this answer
 
cil - Why .NET code compiles to MSIL? - Stack Overflow[^]

Primarily because MSIL is platform-agnostic. If you compiled straight to native code, you'd have to recompile it for every platform you wanted to support.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900