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
327
votes
7 answers

What is the purpose of a stack? Why do we need it?

So I am learning MSIL right now to learn to debug my C# .NET applications. I've always wondered: what is the purpose of the stack? Just to put my question in context: Why is there a transfer from memory to stack or "loading?" On the other hand,…
Jan Carlo Viray
  • 11,856
  • 11
  • 42
  • 63
172
votes
20 answers

What can you do in MSIL that you cannot do in C# or VB.NET?

All code written in .NET languages compiles to MSIL, but are there specific tasks / operations that you can do only using MSIL directly? Let us also have things done easier in MSIL than C#, VB.NET, F#, j# or any other .NET language. So far we have…
Binoj Antony
  • 15,886
  • 25
  • 88
  • 96
152
votes
5 answers

Java's Virtual Machine and CLR

As a sort of follow up to the question called Differences between MSIL and Java bytecode?, what is the (major) differences or similarity in how the Java Virtual Machine works versus how the .NET Framework Common Language Runtime (CLR) works? Also,…
Frank V
  • 25,141
  • 34
  • 106
  • 144
151
votes
11 answers

Dynamically replace the contents of a C# method?

What I want to do is change how a C# method executes when it is called, so that I can write something like this: [Distributed] public DTask Solve(int n, DEvent callback) { for (int m = 2; m < n - 1; m += 1) if (m % n == 0) …
June Rhodes
  • 3,047
  • 4
  • 23
  • 29
150
votes
1 answer

Why does the C# compiler translate this != comparison as if it were a > comparison?

I have by pure chance discovered that the C# compiler turns this method: static bool IsNotNull(object obj) { return obj != null; } …into this CIL: .method private hidebysig static bool IsNotNull(object obj) cil managed { ldarg.0 // obj …
stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
100
votes
3 answers

What is the purpose of hidebysig in a MSIL method?

Using ildasm and a C# program e.g. static void Main(string[] args) { } gives: .method private hidebysig static void Main(string[] args) cil managed { .entrypoint // Code size 2 (0x2) .maxstack 8 IL_0000: nop IL_0001: ret } //…
rbrayb
  • 46,440
  • 34
  • 114
  • 174
100
votes
3 answers

Why does this (null || !TryParse) conditional result in "use of unassigned local variable"?

The following code results in use of unassigned local variable "numberOfGroups": int numberOfGroups; if(options.NumberOfGroups == null || !int.TryParse(options.NumberOfGroups, out numberOfGroups)) { numberOfGroups = 10; } However, this code…
Brandon Martinez
  • 1,330
  • 1
  • 9
  • 13
99
votes
4 answers

Weird performance increase in simple benchmark

Yesterday I found an article by Christoph Nahr titled ".NET Struct Performance" which benchmarked several languages (C++, C#, Java, JavaScript) for a method which adds two point structs (double tuples). As it turned out, C++ version takes about…
vgru
  • 49,838
  • 16
  • 120
  • 201
93
votes
2 answers

Why is !0 a type in Microsoft Intermediate Language (MSIL)?

In many MSIL listings, I have observed the following: System.Nullable`1 etc ... or class !0 etc ... What's the meaning of !0 in these circumstances?
Dragno
  • 3,027
  • 1
  • 27
  • 41
90
votes
4 answers

What does beforefieldinit flag do?

What does beforefieldinit flag do? When I look into the IL of my class I see this flag but I don't know what this flag is actually doing?
Embedd_0913
  • 16,125
  • 37
  • 97
  • 135
89
votes
7 answers

Is there an explanation for inline operators in "k += c += k += c;"?

What is the explanation for the result from the following operation? k += c += k += c; I was trying to understand the output result from the following code: int k = 10; int c = 30; k += c += k += c; //k=80 instead of 110 //c=70 and currently I am…
85
votes
8 answers

Differences between MSIL and Java bytecode?

I'm new to .Net and I'm trying to understand the basics first. What is the difference between MSIL and Java bytecode?
user18055
  • 851
  • 1
  • 7
  • 4
82
votes
18 answers

What's the purpose of the CIL nop opcode?

I'm going through MSIL and noticing there are a lot of nop instructions in the MSIL. The MSDN article says they take no action and are used to fill space if the opcode is patched. They're used a lot more in debug builds than release builds. I know…
Dan Goldstein
  • 23,436
  • 10
  • 47
  • 51
65
votes
6 answers

Call and Callvirt

What is the difference between the CIL instructions "Call" and "Callvirt"?
Eric Smith
  • 5,262
  • 2
  • 33
  • 49
62
votes
1 answer

Profiling a dynamic pinvoke

I am working on MSIL profiler and encountered problems with ManagedToUnmanagedTransition and UnmanagedToManagedTransition callbacks of ICorProfilerCallback interface. What I want to retrieve is an information about method being called (name and…
dud3
  • 621
  • 4
  • 3
1
2 3
70 71