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
13
votes
6 answers

Is C# faster than VB.NET?

You'd think both are the same. But maybe it's the compiler that Microsoft has used, but I've noticed that when compiling two very small programs, identical logic. VB.NET uses more IL instructions. Is it true than that c# must be faster, if only…
Diskdrive
  • 18,107
  • 27
  • 101
  • 167
13
votes
2 answers

What OpCodes were introduced in CLR 4.0?

Are there any IL opcodes that are new in .NET 4.0 as compared to 3.5, and if so, where can I find a list of them?
Timwi
  • 65,159
  • 33
  • 165
  • 230
13
votes
2 answers

Why does tail call optimization need an op code?

So I've read many times before that technically .NET does support tail call optimization (TCO) because it has the opcode for it, and just C# doesn't generate it. I'm not exactly sure why TCO needs an opcode or what it would do. As far as I know, the…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
13
votes
4 answers

Why is it not possible to get local variable names using Reflection?

If I have a code like this: public class Program { public static void Main() { string bar = ""; int foo = 24; } } I can get the local variables declared in Main using: var flag = BindingFlags.Static |…
Selman Genç
  • 100,147
  • 13
  • 119
  • 184
13
votes
4 answers

What is the difference between ldc.i4.s and ldc.i4?

I was studying about the Intermediate Language for C#(IL) and came across the following piece of code:- //Add.il //Add Two Numbers .assembly extern mscorlib {} .assembly Add { .ver 1:0:1:0 } .module add.exe .method static void main() cil…
Pratik Singhal
  • 6,283
  • 10
  • 55
  • 97
13
votes
2 answers

"nested if" versus "if and" performance using F#

The following code results in slow1 = 1323 ms, slow2 = 1311 ms and fast = 897 ms. How is that possible? Here: Nested or not nested if-blocks? they mention that Any modern compiler, and by that I mean anything built in the past 20 years, will…
Oldrich Svec
  • 4,191
  • 2
  • 28
  • 54
13
votes
2 answers

Is it possible to skip visibility checks when generating dynamic IL with MethodBuilder's?

When generating IL using DynamicMethod it's possible to call methods and access fields that would be otherwise un-accessible if you provide 'true' for the restrictedSkipVisibility parameter in the DynamicMethod constructor I would prefer to emit…
Brandon Cuff
  • 1,438
  • 9
  • 24
12
votes
3 answers

Is there a simple way to obtain all the local variables in the current stack frame in C# (or CIL)

Following my previous question, in which I wanted to dump all the variables in the stack (from the current and all the previous frame) that can be seen here: Is there a way to examine the stack variables at runtime in C#? I was suggested to…
cloudraven
  • 2,484
  • 1
  • 24
  • 49
12
votes
2 answers

Creating a DynamicType in .NET implementing an interface but using member implementations from a base class

I am attempting to generate a dynamic class implementing an interface, but where one or more of the members already exists in the base. I compiled the following code in C# and examined it in reflector to see what the C# compiler does. class…
Brian Reichle
  • 2,798
  • 2
  • 30
  • 34
12
votes
3 answers

Why does adding an extra field to struct greatly improves its performance?

I noticed that a struct wrapping a single float is significantly slower than using a float directly, with approximately half of the performance. using System; using System.Diagnostics; struct Vector1 { public float X; public Vector1(float…
Varon
  • 33
  • 1
  • 10
12
votes
4 answers

Are Bytecode and Assembly Language the same thing?

The question might seem odd, but I am still trying to grasp the concepts of virtual machines. I have read several answers, but I still don't get if Java bytecode (and MSIL as well) is the same as assembly language. As far as I understand both…
12
votes
2 answers

Is changing the size of a struct a breaking change in C#?

Just curious, is changing the size of a struct/value type a breaking change in C#? Structs tend to be more sensitive in terms of memory layout since altering them directly affects the size of arrays/other structs. Are there any examples of code that…
James Ko
  • 32,215
  • 30
  • 128
  • 239
12
votes
1 answer

What is the purpose of the extra ldnull and tail. in F# implementation vs C#?

The following C# function: T ResultOfFunc(Func f) { return f(); } compiles unsurprisingly to this: IL_0000: ldarg.1 IL_0001: callvirt 05 00 00 0A IL_0006: ret But the equivalent F# function: let resultOfFunc func =…
Asik
  • 21,506
  • 6
  • 72
  • 131
12
votes
4 answers

What is the (fnptr)* type and how to create it?

The following IL code creates a Type instance named (fnptr)* (token 0x2000000 - invalid, module mscorlib.dll). ldtoken method void* ()* call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype…
IS4
  • 11,945
  • 2
  • 47
  • 86
12
votes
1 answer

Wrong file path and line number in Exception stack traces from dynamic code

We are using System.Reflection.Emit to generate code at runtime from source code (yes - as in a compiler). We provide correct symbol information to the ILGenerator with MarkSequencePoint etc, and enable all debug flags on the AssemblyBuilder. The…
Duckers
  • 140
  • 6