user2619824
user2619824

Reputation: 478

Relationship between compiling in x86/x64 and MSIL

So I know that if you compile for Any CPU, you get an MSIL output. If you compile as x86, you get an x86 output.

My understanding of the process is like as follows

.NET Code -> Compiler -> MSIL -> JIT compiled in CLR -> Native Instruction

My question is if you compile in x86/x64, does that skip the MSIL -> JIT compiled in CLR step above? Or is my understanding off?

Upvotes: 3

Views: 2345

Answers (1)

Iridium
Iridium

Reputation: 23731

Your understanding is not quite correct. Providing the assembly consists of only managed code, it will always be compiled to pure MSIL, regardless of the compiler setting (AnyCPU/x86/x64), so even if you compile as x86, you still get MSIL.

If you compile as AnyCPU, then your assembly can run as or be loaded into a 32 bit or 64 bit process, whereas if it's compiled as x86, it can only run as (or be loaded into) a 32 bit process. Similarly, when compiled as x64, it can only run as (or be loaded into) a 64 bit process. The same MSIL is used in either case, and the JIT compiles the MSIL to the required 32/64 bit native code.

Upvotes: 4

Related Questions