Enhancements for C2, the Compiler Behind VC++ and Native .NET

| by Jonathan Allen Follow 576 Followers on Apr 30, 2015. Estimated reading time: 2 minutes |

Most developers don’t know much about C2, but it is a vital part of the Windows development lifecycle. It acts as the backend compiler for Visual C++, .NET natively compiled code, compiled T-SQL, and Objective-C on Windows.

Security in C++ is hard. The language is inherently unsafe when it comes to memory and it only takes one dangling pointer to create a major vulnerability. In order to mitigate the danger this poses, Microsoft introduced a new compiler switch called /Guard that changes the way virtual methods are called. This required major changes both the compiler, linker and operating system so it is only available on Windows 8.1 and higher.

Even though CPUs are more powerful year after year, that power isn’t being realized in terms of raw clock speed. So C++ needs to improve its support for resumable functions, a.k.a. co-routines. The cost of resume/suspend is equivalent to a normal function call, allowing for a zero overhead abstraction over existing async facilities

Control flow can now be vectorized, allowing C++ to speed up loops that contain simple if statements. Early benchmarks show improvements from 229 to 600% improvement in performance.

Normally performance improvements like this come with a substantial increase in build times. With whole application incremental compiling, the build times were actually decreased from a few percentage points to an order of magnitude. This is made possible by caching the ASTs that VC++ generates during the compilation process so that it can be fed back into the pipeline.

You can further improve the compilation speed by using /debug:fastlink to switch to the new PDB format. PDB generation, which is necessary for debugging, is often the most costly step in the build process. Under the new PDB format, the compiler generates and modifies lookup tables instead of regenerating the whole PDB each time.

.NET developers may be tempted to think all of this doesn’t matter to them, but under the Windows 10/Universal Apps model all .NET applications are natively compiled before they are delivered to the customer. This is done by piping the IL code into C2, the backend compiler for VC++.

C2 is also used to compile Objective-C for Windows. More on this topic, see our follow-up article, Compiling Objective-C into C++ with Visual Studio or watch the Channel 9 video Compiling Objective-C Using the Visual Studio 2015 C++ Code Generation that Builds Windows, SQL, .Net, and Office.

Rate this Article

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread


Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you