.netc++compiler-constructioncil

Is C++ converted into CIL?


I have been a long time C# and .NET developer, and have been playing with the idea of learning C++.

One of the primary reasons I have been thinking about this, is how much faster C++ can be over apps using .NET. But am I right in assuming that if I write a C++ app in Visual Studio, and/or reference .NET libraries in a C++ application that, that C++ is converted in CIL (just like C#) - and therefore I'd lose any benefit from coding in it?

So my question is really this: are C++ components of an application referencing .NET assemblies compiled in the "traditional" way, or compiled into CIL?


Solution

  • Well it's a bit more complicated than that. There are actually two totally different versions of .NET-supporting C++.

    The old one, Managed Extensions for C++, was the only option available in Visual C++ 2002/2003. It's available in newer compilers under the option /clr:oldSyntax. It's kinda clumsy as it tries hard to integrate with standard C++, so all new keywords (and there's lots of them) are prefixed with double underscores, etc. Code generated by this compiler is a mixture of native and MSIL code, dubbed IJW "it just works".

    The new one, called C++/CLI, is a clean new language available in Visual C++ 2005 and newer. Most importantly, it supports several modes of code generation. The /clr option again generates a IJW mixture of native and MSIL code. /clr:pure results in a managed-only assembly, although it may translate native types into corresponding .net structures. The code therefore may not be type-safe and can use pointer arithmetic, pretty much like C# with /unsafe. And the strictest of options is /clr:safe, which produces type-safe, verifiable MSIL-only assembly, exactly like C# compiler does (without /unsafe, that is).

    For differences between MC++ and C++/CLI, see wikipedia.

    For description of the compiler switches, see MSDN.

    PS. The .NET byte-code is called either MSIL (Microsoft Intermediate Language) or CIL (Common Intermediate Language). MIL can stand for Media Integration Layer, the undocumented low-level library used by WPF and Vista Desktop Window Manager.