Sign in to follow this  
Surrix

How is C# compiled?

Recommended Posts

At University I have learned the ins and outs of C++. I have recently been looking for an internship over the summer and found a lot of businesses looking for C# programmers. This has led me to start learning C# because this seems to be where the programming world is heading (although maybe not the gaming world but I don't know). Anyways from the book I'm currently reading I've read on how C# is compiled. The book said the code is compiled into a form the CLR can understand and then from there taken down to a form the CPU understands. Is this like Java in that programs are compiled into Java byte code and then at runtime are translated into a language the CPU can understand. Or does the compiling and linking process take it all the way down to a language the CPU can understand right away thus at runtime there is nothing translating it. PS: On a side note is it the general feeling that game development for the Windows platform will move to .Net or will it stay with C++?

Share this post


Link to post
Share on other sites
This is only a light overview - somewhere on Microsoft's site (I'll Google and edit if I find it) there's highly technical documentation of how exactly it all works.

In general, though: the .NET compilers take your code and compile it to MSIL (Microsoft Intermediate Language). It writes this to a modified PE executable file, with the header modified so that the .NET JIT (Just-In-Time) compiler gets called to compile the IL into machine code for the appropriate platform. It's slightly more complicated, because sometimes this compilation is cached (and the ngen tool forces it to be).

Share this post


Link to post
Share on other sites
It works a lot like Java, except Sun's Java Virtual Machine will not always compile Java bytecode down to machine code. It identifies critical methods and will only JIT-compile those. The CLR will JIT-compile everything, so no bytecode interpretation is done anywhere (AFAIK).

Games with C#? It's definitely possible and it has been done before, but you'll always have to struggle with automatic garbage collection and hackery is needed to avoid losing object references. I'm pretty sure that, especially to protect their investments, commercial game developers are going to stick with C++ for a long time to come though.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this