Abstract
In this chapter, I’ll walk through a number of code snippets written in various .NET languages and demonstrate what the differences are in their assemblies. I’ll compare and contrast debug and release builds. You’ll get a chance to look at how different language constructs are translated into CIL by the different compilers. I’ll show you how a piece of code in one language may not create the output you expect. As you’ll see throughout this chapter, what you code is not always what you get. By knowing CIL, you’ll be able to figure out what’s really going on.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Reference
Technically, the C# compiler will tell you if a variable is not being used as is the case with i, but it won’t be able to make the optimization with someType.
In this case, it’s easy to see that i will be 1 when the method is finished, but in more complex cases it may be nice to see the value before the method exits.
Later on, I’ll demonstrate a more convoluted example with overridden and overloaded methods.
For a listing of the optimizations that C#’s compiler will perform, please read the section “Optimizations” in Chapter 36 of Eric Gunnerson’s book, A Programmer’s Introduction to C#, Second Edition (Apress, 2001).
See Section 8.4 of the Visual Basic Language Specification of the.NET SDK.
This isn’t possible with ATL out of the box; see http: //www.sellsbrothers.com/tools/default.aspx for a workaround to this problem if you run into it and you’re still coding COM servers in ATL.
The reason this worked with the Oberon example in Chapter 1 is because the interface and class methods matched, so the runtime was able to determine that the interface was implemented correctly.
I think that most vendors will do this before they publish their assemblies. However, it doesn’t hurt to do a quick check on them before you use them—the time it takes to run PEVerify on an assembly relative to the time it may take to figure out why something isn’t working as expected is worth it in my book.
I have to admit, I’ve used it on VB projects in the past, primarily in the error handling code itself. But I’ve made a resolution to never use this feature as long as I live, especially after 216 seeing what happens when it’s used!
Right before this book was published, a research paper was released on adding constructs similar to active objects to C#. It’s titled “Modern Concurrency Abstractions for C#,” and you can download it athttp://research.microsoft.com/Users/luca/Papers/Polyphony%20ECOOP.A4.pd-F.
Technically, this is documented behavior according to a white paper from the makers of the Oberon compiler for.NET (http: //www. oberon. ethz. ch/oberon. net/whitepaper/ ActiveoberonNetWhitePaper. pdf). See Section 6.1 in the paper for details.
Unfortunately, IntelliSense won’t show the property methods, even though they’re public. But if you simply type them in, everything will compile normally.
Rights and permissions
Copyright information
© 2002 Jason Bock
About this chapter
Cite this chapter
Bock, J. (2002). .NET Languages and CIL. In: CIL Programming: Under the Hood™ of .NET. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4302-0845-7_6
Download citation
DOI: https://doi.org/10.1007/978-1-4302-0845-7_6
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4302-5156-9
Online ISBN: 978-1-4302-0845-7
eBook Packages: Springer Book Archive