English 中文(简体)
What extensions to the language does the C# compiler implement?
原标题:

In Eric Lippert s blog entry on umpires and the C# compiler and spec, he makes this statement:

(or deliberately; we implement a small number of extensions to the formal C# language)

And that got me wondering, what extensions is he referring to, exactly?

最佳回答

In his comments he gives some answers, (and he has given some in past blog entries)

Handling of the constant 0, typed references (http://www.eggheadcafe.com/articles/20030114.asp), type analysis of conditional expressions...

But what he s trying to say is that it shouldn t really matter to the end user, because they re weird corner cases (like the "(m=> (m=> (m=> ..." case) that are needed to help the compiler, and aren t part of the spec.

Follow the spec and you should be fine.

(below added 1:42 pm)

So, I said "Follow the spec and you should be fine." That s really all the advice that I can help you with. Yes, there are some places where the compiler deviates from the spec. But these aren t really documented, partially because they don t know what to do. Do they fix the compiler to adhere to the spec? Or do they change the spec for the weird behavior. That s basically the whole point of the handling of zero article:

http://blogs.msdn.com/ericlippert/archive/2006/03/29/the-root-of-all-evil-part-two.aspx

That s kinda the point of these extensions. They re (for the most part) undocumented, because (for the most part) they re unknown. Who knows, maybe there s some really weird handling of Flags enums that doesn t quite conform to the spec, but we wouldn t really know about it until we do some really weird thing with them. The flags enumerations have been tested, and should mostly follow the spec, so when I say "follow the spec and you should be fine" I mean precisely that. You might not be fine, because there are gotchas. but Eric is doing what he can to fix these problems, and make them known in the interim.

问题回答

Not counting bugs, the most common example is varargs; but much of COM interop is extensions; for example interface constructors.

17.5 in the spec basically says "anything in System.Runtime.InteropServices can do what it wants". MSDN documents this here.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签