Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compatibility of .NET csc and Mono mcs

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?

like image 554
Jake Petroules Avatar asked May 01 '11 17:05

Jake Petroules


1 Answers

A lot of things are not fully defined in the spec, or are implementation-specific extensions.

Examples of not-fully-specified:

  • the synchronisation semantics of field-like events; this is explicitly open to implementations in the ecma spec; it is stricty defined in the MS spec, but uses a different version in c# 4.0 which does not yet appear in the formal spec, IIRC
  • Expression construction (from lambdas); is simply "defined elsewhere" (actually, it isn't)

Examples of implementation extensions:

  • P/Invoke
  • COM interface handling (i.e. how you can call 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.

like image 91
Marc Gravell Avatar answered Sep 30 '22 09:09

Marc Gravell