cil

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

喜欢而已 提交于 2019-11-28 02:58:32
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 works fine (though, ReSharper says the = 10 is redundant): int numberOfGroups = 10; if(options.NumberOfGroups == null || !int.TryParse(options.NumberOfGroups, out numberOfGroups)) { numberOfGroups = 10; } Am I missing something, or is the compiler not liking my || ? I've narrowed this down to dynamic causing the issues ( options was a dynamic variable in

Differences between MSIL and Java bytecode?

佐手、 提交于 2019-11-28 02:46:14
I'm new to .Net and I'm trying to understand the basics first. What is the difference between MSIL and Java bytecode? Motti First off let me say that I don't think that the subtle differences between Java bytecode and MSIL is something that should bother a novice .NET developer. They both serve the same purpose of defining an abstract target machine which is a layer above the physical machine being used in the end. MSIL and Java bytecode are very similar, in fact there is a tool called Grasshopper which translates MSIL to Java bytecode, I was part of the development team for Grasshopper so I

MS C# compiler and non-optimized code

五迷三道 提交于 2019-11-28 02:41:48
问题 Note: I noticed some errors in my posted example - editing to fix it The official C# compiler does some interesting things if you don't enable optimization. For example, a simple if statement: int x; // ... // if (x == 10) // do something becomes something like the following if optimized: ldloc.0 ldc.i4.s 10 ceq bne.un.s do_not_do_something // do something do_not_do_something: but if we disable optimization, it becomes something like this: ldloc.0 ldc.i4.s 10 ceq ldc.i4.0 ceq stloc.1 ldloc.1

Can/does the (forward) pipe operator prevent tail call optimization?

拈花ヽ惹草 提交于 2019-11-28 02:38:41
问题 For a parameter optimization problem at work I wrote a genetic algorithm to find some good settings because a brute-force solution is unfeasible. Unfortunately, when I return in the morning, most of the time I'm presented with a StackOverflowException . I've been using F# for quite some time now so I'm aware of TCO and the need for functions with accumulator arguments and generally use that form. After a lot of searching I think I was able to nail to the code that triggered the exception:

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

北城余情 提交于 2019-11-28 02:31:04
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, why is there a transfer from stack to memory or "storing"? Why not just have them all placed in the memory? Is it because it's faster? Is it because it's RAM based? For efficiency? I'm trying to grasp this to help me understand CIL codes much more deeply. UPDATE: I liked this question so much I made it the subject of my blog on November 18th 2011 .

Is there an API for verifying the MSIL of a dynamic assembly at runtime?

ε祈祈猫儿з 提交于 2019-11-27 23:38:55
问题 When using Reflection.Emit to build an assembly at runtime, I'd like to verify the assembly MSIL before saving to disc. Like PEVerify but at runtime. Is there such an API? 回答1: It seems that peverify.exe is a front-end to c:\Windows\Microsoft.NET\Framework\v4.0.30319\peverify.dll (or c:\Windows\Microsoft.NET\Framework\v2.0.50727\peverify.dll for CLR 2.0), which is a native DLL (actually, peverify.exe is also native) I don't see this documented anywhere so it's probably not a public API. You

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

风格不统一 提交于 2019-11-27 23:04:10
问题 Reading sources of Array2D module, I've stumbled upon this interesting construct in implementation of many core functions, for example: [<CompiledName("Get")>] let get (array: 'T[,]) (n:int) (m:int) = (# "ldelem.multi 2 !0" type ('T) array n m : 'T #) I can only assume that this is the syntax to inline CIL and is used here obviously to gain performance benefits. However, when I've tried to use this syntax in my program, I get an error: warning FS0042: This construct is deprecated: it is only

Compiler generated sealed class for delegate keyword contains virtual methods

半城伤御伤魂 提交于 2019-11-27 20:58:14
问题 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 are marked public virtual extern but interestingly the class itself is marked sealed . Virtual methods defined in a sealed class not only strikes as counter-intuitive but are actually illegal in C#. So my question is, is there a specific reason for

Differences between MSIL and Java bytecode?

只谈情不闲聊 提交于 2019-11-27 19:13:55
问题 I'm new to .Net and I'm trying to understand the basics first. What is the difference between MSIL and Java bytecode? 回答1: First off let me say that I don't think that the subtle differences between Java bytecode and MSIL is something that should bother a novice .NET developer. They both serve the same purpose of defining an abstract target machine which is a layer above the physical machine being used in the end. MSIL and Java bytecode are very similar, in fact there is a tool called

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

廉价感情. 提交于 2019-11-27 19:13:35
问题 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, why is there a transfer from stack to memory or "storing"? Why not just have them all placed in the memory? Is it because it's faster? Is it because it's RAM based? For efficiency? I'm trying to grasp this to help me understand CIL codes much more