Questions tagged [cil]

Common Intermediate Language is the object-oriented assembly language used by the .NET Framework, .NET Core, and Mono. .NET languages compile to CIL, which is assembled into an object code that has a bytecode-style format.

Common Intermediate Language (CIL, pronounced either "sil" or "kil") (formerly called Microsoft Intermediate Language or MSIL, and sometimes informally called IL) is the lowest-level human-readable programming language defined by the Common Language Infrastructure (CLI) specification and is used by the .NET Framework, .NET Core, and Mono.

Languages which target a CLI-compatible runtime environment compile to CIL, which is assembled into an object code that has a bytecode-style format. CIL is an object-oriented assembly language, and is stack-based. Its bytecode is translated into native code or executed by a virtual machine.

For CIL the C Intermediate Language (a subset of C), use .

1064 questions
14
votes
1 answer

Why does the C# compiler explicitly declare all interfaces a type implements?

The C# compiler seems to explicitly note all interfaces it, and its base classes implement. The CLI specs say that this is not necesary. I've seen some other compilers not emit this explicitly, and it seems to work fine. Is there any difference or…
MichaelGG
  • 9,976
  • 1
  • 39
  • 82
14
votes
5 answers

IS C++ converted into MSIL?

I have been a long time C# and .Net developer, and have been playing with the idea of learning c++. One of the primary reasons I have been thinking about this, is how much faster C++ can be over apps using the .Net framework. But am I right in…
Ash
  • 24,276
  • 34
  • 107
  • 152
14
votes
2 answers

Why is IL.Emit method adding additional nop instructions?

I have this code that emits some IL instructions that calls string.IndexOf on a null object: MethodBuilder methodBuilder = typeBuilder.DefineMethod( "Foo", …
Selman Genç
  • 100,147
  • 13
  • 119
  • 184
14
votes
2 answers

.NET decompiler distinction between "using" and "try...finally"

Given the following C# code in which the Dispose method is called in two different ways: class Disposable : IDisposable { public void Dispose() { } } class Program { static void Main(string[] args) { using (var…
Laurent De Cant
  • 493
  • 1
  • 4
  • 19
14
votes
2 answers

Why Local Functions generate IL different from Anonymous Methods and Lambda Expressions?

Why the C# 7 Compiler turns Local Functions into methods within the same class where their parent function is. While for Anonymous Methods (and Lambda Expressions) the compiler generates a nested class for each parent function, that will contain all…
KeyBored
  • 601
  • 4
  • 14
14
votes
3 answers

What is the first argument in a parameterless constructor?

I have simple program like this: public class Foo { public Foo() { } public int MyInt { get; set; } = 10; public List MyList { get; set; } = new List(); } public class Program { static public void Main() { …
Alex Aparin
  • 4,393
  • 5
  • 25
  • 51
14
votes
1 answer

Applying MethodImplOptions.AggressiveInlining to F# functions

The attribute System.Runtime.CompilerServices.MethodImplAttribute can be used to give hints to the JIT compiler about how to handle the decorated method. In particular, the option MethodImplOptions.AggressiveInlining instructs the compiler to inline…
Frank
  • 2,738
  • 19
  • 30
14
votes
4 answers

Weird performance behavior

So I have this 2 methods which suppose to multiply a 1000 items long array of integers by 2. The first method: [MethodImpl(MethodImplOptions.NoOptimization)] Power(int[] arr) { for (int i = 0; i < arr.Length; i++) { arr[i] = arr[i] +…
Tamir Vered
  • 10,187
  • 5
  • 45
  • 57
14
votes
1 answer

Why is the CLR's jmp instruction unverifiable?

I've known about the jmp instruction for awhile, but it never struck me as being even remotely unsafe. I recently had cause to check the CIL specs and was very surprised to discover jmp is considered unverifiable.
naasking
  • 2,514
  • 1
  • 27
  • 32
14
votes
4 answers

Visual Studio/RAD support for coding directly in IL?

For the longest time I've been curious to code directly in Intermediate Language as an academic endeavour, to gain a better understanding of what's happening "under the hood". Does anybody provide Visual Studio support for *IL in the form of:…
John K
  • 28,441
  • 31
  • 139
  • 229
14
votes
2 answers

What is the point of nop in CIL

So I wrote the following code in C#. class Test { int a; System.IO.StreamReader reader; public Test() { a = 5; reader = new System.IO.StreamReader(String.Empty); } } And the constructor of the class in IL looks…
Dimitri
  • 2,798
  • 7
  • 39
  • 59
14
votes
1 answer

What does the symbol <> mean in MSIL?

I have this code after decompile SampleClass sampleClass; SampleClass <>g__initLocal0; int y; sampleClass = null; Label_0018: try { <>g__initLocal0 = new SampleClass(); <>g__initLocal0.X = 5; …
Jacek
  • 11,661
  • 23
  • 69
  • 123
14
votes
2 answers

Does setting the platform when compiling a c# application make any difference?

In VS2012 (and previous versions...), you can specify the target platform when building a project. My understanding, though, is that C# gets "compiled" to CIL and is then JIT compiled when running on the host system. Does this mean that the only…
AJ.
  • 1,621
  • 1
  • 10
  • 23
13
votes
2 answers

Why Is the .MaxStack Directive Optional in MSIL Code?

I am learning assembly language in my spare time. Can anyone explain why .maxstack appears to be optional in this program. I have tried to find the answer online and in my book with no such luck i.e. the program will compile and run with .Maxstack…
w0051977
  • 15,099
  • 32
  • 152
  • 329
13
votes
2 answers

What is the Implementation of Generics for the NET Common Language Runtime

When you use generic collections in C# (or .NET in general), does the compiler basically do the leg-work developers used to have to do of making a generic collection for a specific type. So basically . . . it just saves us work? Now that I think…
richard
  • 12,263
  • 23
  • 95
  • 151