C# compiler doesn’t optimize unnecessary casts
My guess is that you have discovered a minor bug in the optimizer. There is all kinds of special-case code in there for arrays. Thanks for bringing it to my attention.
My guess is that you have discovered a minor bug in the optimizer. There is all kinds of special-case code in there for arrays. Thanks for bringing it to my attention.
I think a big reason is that it’s quite hard to create a new IL instruction and it could affect a lot of tools, including external ones (ILGenerator, ilasm, ildasm, PEVerify, Reflector, PostSharp, …). But creating a new InternalCall method? That’s almost as simple as writing the method in C# (I assume, I didn’t look … Read more
While this method indeed just uses sizeof IL instruction – there is a difference with regular sizeof operator, because this operator cannot be applied to arbitrary types: Used to obtain the size in bytes for an unmanaged type. Unmanaged types include the built-in types that are listed in the table that follows, and also the … Read more
C# compiler does not give you any guarantees about tail-call optimizations because C# programs usually use loops and so they do not rely on the tail-call optimizations. So, in C#, this is simply a JIT optimization that may or may not happen (and you cannot rely on it). F# compiler is designed to handle functional … Read more
Note: as of C# 6, this isn’t required – but you should be using read-only automatically-implemented properties with C# 6 anyway… this() makes sure that the fields are definitely assigned as far as the compiler is concerned – it sets all fields to their default values. You have to have a fully constructed struct before … Read more
The profiler APIs are returning metadata specified in the managed code, normally via the DllImportAttribute. In the case of the ‘dynamic pinvoke’ which uses the Marshal.GetDelegateForFunctionPointer method, the module and function names were never specified as metadata and not available. An alternative approach to dynamic pinvoke declarations that includes the required metadata will probably avoid … Read more
When the runtime executes a call instruction it’s making a call to an exact piece of code (method). There’s no question about where it exists. Once the IL has been JITted, the resulting machine code at the call site is an unconditional jmp instruction. By contrast, the callvirt instruction is used to call virtual methods … Read more
NOPs serve several purposes: They allow the debugger to place a breakpoint on a line even if it is combined with others in the generated code. It allows the loader to patch a jump with a different-sized target offset. It allows a block of code to be aligned at a particular boundary, which can be … Read more
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 … Read more
An operation like a op= b; is equivalent to a = a op b;. An assignment can be used as statement or as expression, while as expression it yields the assigned value. Your statement … k += c += k += c; … can, since the assignment operator is right-associative, also be written as k … Read more