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
25
votes
1 answer

Why the compiler adds an extra parameter for delegates when there is no closure?

I was playing with delegates and noticed that when I create a Func like the example below: Func func1 = (x, y) => x * y; The signature of the compiler generated method is not what I expected: As you can see it takes an…
Selman Genç
  • 100,147
  • 13
  • 119
  • 184
24
votes
5 answers

Is there any benefit to making a C# field read-only if its appropriate?

I am working on a project using ReSharper. On occasion it prompts me that a field can be made readonly. Is there any performance or other benefit to this? I am presuming the benefits would be quite low-level, or would any benefits be purely…
Matt
  • 2,730
  • 4
  • 28
  • 35
24
votes
10 answers

Why are static classes considered “classes” and “reference types”?

I’ve been pondering about the C# and CIL type system today and I’ve started to wonder why static classes are considered classes. There are many ways in which they are not really classes: A “normal” class can contain non-static members, a static…
Timwi
  • 65,159
  • 33
  • 165
  • 230
24
votes
2 answers

What is the (# ... #) syntax seen in F# standard library implementation?

Reading sources of Array2D module, I've stumbled upon this interesting construct in implementation of many core functions, for example: [] let get (array: 'T[,]) (n:int) (m:int) = (# "ldelem.multi 2 !0" type ('T) array n m : 'T…
MisterMetaphor
  • 5,900
  • 3
  • 24
  • 31
23
votes
1 answer

Possible bug in C# JIT optimizer?

Working on a SQLHelper class to automate stored procedures calls in a similar way to what is done in the XmlRpc.Net library, I have hit a very strange problem when running a method generated manually from IL code. I've narrowed it down to a simple…
Álvaro Iradier
  • 295
  • 2
  • 12
23
votes
1 answer

Getting the field a MemberRef metadata token refers to

Fair warning, this may be a tad esoteric and tricky. Given a MemberRef (more explanation below) extracted from a CIL stream, how do you figure out what field, if any, it points to (and get a FieldInfo for it)? Here's what I've figured out so…
Kevin Montrose
  • 22,191
  • 9
  • 88
  • 137
23
votes
5 answers

How can I get current values of locals and parameters on the stack?

In a .NET application I have some points where I need to collect some debug info about the current thread state. I can obtain some information new StackTrace() constructor. In particular, I can get the list of current stack frames, including…
X.C.
  • 391
  • 1
  • 5
20
votes
7 answers

Indexing arrays with enums in C#

I have a lot of fixed-size collections of numbers where each entry can be accessed with a constant. Naturally this seems to point to arrays and enums: enum StatType { Foo = 0, Bar // ... } float[] stats = new…
gix
  • 5,737
  • 5
  • 34
  • 40
20
votes
3 answers

Behavior of F# "unmanaged" type constraint

F# supports a type constraint for "unmanaged". This is not the same as a value type constraint like "struct" constraints. MSDN notes that the behavior of the unmanaged constraint is: The provided type must be an unmanaged type. Unmanaged types are…
vcsjones
  • 138,677
  • 31
  • 291
  • 286
20
votes
3 answers

Is there a way to see the native code produced by theJITter for given C# / CIL?

In a comment on this answer (which suggests using bit-shift operators over integer multiplication / division, for performance), I queried whether this would actually be faster. In the back of my mind is an idea that at some level, something will be…
AakashM
  • 62,551
  • 17
  • 151
  • 186
20
votes
1 answer

Why does the type System.__ComObject claim (sometimes) to be public when it is not?

Just an oddity I happened to discover when I was reflecting over all types to check something else out of curiosity. Why does the class System.__ComObject of the assembly mscorlib.dll (sometimes?) claim to be public when in fact it seems to be…
Jeppe Stig Nielsen
  • 60,409
  • 11
  • 110
  • 181
19
votes
1 answer

Where can I find a list of escaped characters in MSIL string constants?

I've written a program (in C#) that reads and manipulates MSIL programs that have been generated from C# programs. I had mistakenly assumed that the syntax rules for MSIL string constants are the same as for C#, but then I ran into the following…
RenniePet
  • 11,420
  • 7
  • 80
  • 106
19
votes
1 answer

Making a CLR/.NET Language Debuggable

What are some resources for making a CLR/.NET language debuggable? I'm developing an ActionScript 3 to IL compiler, which uses DLR CallSites and CallSiteBinders to handle the dynamic aspects of the otherwise static programming language. I'm looking…
19
votes
5 answers

What are the best resources for learning CIL (MSIL)

I'm an expert C# 3 / .NET 3.5 programmer looking to start doing some runtime codegen using System.Reflection.Emit.DynamicMethod. I'd love to move up to the next level by becoming intimately familiar with IL. Any pointers (pun intended)?
TheSoftwareJedi
  • 34,421
  • 21
  • 109
  • 151
19
votes
4 answers

Compiler generated sealed class for delegate keyword contains virtual methods

When delegate keyword is used in C#, the C# compiler automatically generates a class derived from System.MulticastDelegate class. This compiler generated class contains 3 methods as well: Invoke, BeginInvoke and EndInvoke. All these three methods…
Amit Mittal
  • 2,646
  • 16
  • 24
1 2
3
70 71