I know .NET and Mono are binary compatible but given a set of source code, will csc and mcs produce the exact same 100% identical binary CLI executable? Would one be able to tell whether an executable was compiled with csc or mcs?
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
- Should I use static function in c# where many call
I'm sure they don't produce the same IL from the same sourcecode. Even different versions of the MS C# compiler don't.
The optimizer will work differently and create slightly different code.
I expect larger differences in the implementation of complex features such as iterators, local variable captured for lamdas,...
Then there are arbitrary compiler generated names, for example for anonymous types. No reason why they should use the same naming scheme for them.
I wouldn't be surprised if there was some assembly metadata containing the name and version of your compiler too.
A lot of things are not fully defined in the spec, or are implementation-specific extensions.
Examples of not-fully-specified:
Expression
construction (from lambdas); is simply "defined elsewhere" (actually, it isn't)Examples of implementation extensions:
new
on an interface)So no: it is not guarantees to have the same IL, either between csc or [g]mcs - but even between different versions of csc.
Even more: depending on debug settings, optimizations being enabled or not, and some compilation constants being defined (such as DEBUG or TRACE), the same compiler will generate different code.