CIL: Difference between revisions

811 bytes added ,  4 years ago
m
fix links
[unchecked revision][unchecked revision]
(fix: 'pinned' italic)
m (fix links)
 
(4 intermediate revisions by 3 users not shown)
Line 1:
{{stub}}
 
The '''Common Intermediate Language''' ('''CIL''', formerly '''MSIL''') is a byte code intermediate language used in the [[.NET Framework]]. ItCode which compiles to CLI byte code is considered 'managed code' and can be created by any [[CLI]] compatible compiler (such as the [[C Sharp|C# Compiler]], and executed by the [[Virtual Execution System]] (VES). It is CPU and platform independent.
 
Most of the time, developers will not be programming directly in CIL but use a higher level language such as [[C Sharp|C#]], [[C++/CLI]], [[Visual Basic .NET]] and [[J#]]. However, CIL has it'sits own assembly language which can be assembled by ILAsm (<code>ilasm.exe</code>). To display the byte code in assembly language, the CIL disassembler ILDAsm (<code>ildasm.exe</code>) is used. However, some specialized tools such as .NET Reflector can represent the byte code as any of the supported higher level languages, such as C#, including the classes, methods and other metadata.
 
==ManagedSafe and unmanagedunsafe code==
The CIL byte code iscan soeither calledbe managedconsidered codesafe or unsafe. By default, all C# is safe, which means that the execution system knows where all the data is, all the time. Therefore it is not possible to use pointers in managedsafe code. Thanks to this property, the most common security and stability problems are eliminated, such as buffer overflows and dangling pointers. A [[Garbage collection|garbage collector]] is employed to use the memory as efficient as possible.
 
===Unsafe code===
Although pointers are not possible in managedsafe code, CIL supports unmanagedunsafe code which does have support for pointers. UnmanagedUnsafe code is contained in blocks of code which is marked 'unsafe', and in C# it uses the same syntax as C and C++. Objects can be ''pinned'' so that the [[Garbage collection|garbage collector]] doesn't move the data around and pointers remain valid. Using unsafe code is perfectly legal, although discouraged in normal application programming, and may be used to write kernel-level methods.
 
==Executing CIL Code==
CIL code is executed by a [[Virtual Execution System]] much like Java byte code. Usually this is in the form of a [[Just In Time compiler]], which translates the byte code into a native machine code, usually utilizing optimizations specific to that processor (for example SSE if available). [http://www.mono-project.com Mono] is an open-source .NET project, which consists of an CIL JIT'er (and interpreter for unsupported architectures) as well as a C#->CLI compiler. The JIT'er and can be [http://www.mono-project.com/Embedding_Mono embedded] in to any program or stand alone. The basic JIT'er and compiler is written in C and only requires the C Standard Library to run.
 
==Metadata==
170

edits