In-Depth

The Evolution of Visual C++ in Visual Studio 2010

C++ developers will see major improvements -- beyond support for Windows 7 APIs -- in Visual C++ 2010.

With the release of Visual Studio 2010, several improvements have been made to make life easier for C++ developers. The three areas of focus for Visual C++ 2010 include a better programming model, overall performance and productivity, and support for Windows 7 applications with an updated MFC Library.

Specifically, Visual Studio 2010 enables a more modern programming model by adding core C++ language features from the upcoming C++0x standard and overhauling the standard library to take advantage of the new language features. There are new parallel programming libraries and tools to simplify the creation of parallel programs.

Visual Studio 2010 has made great strides in performance and developer productivity. The new Windows Presentation Foundation (WPF)-based IDE is more extensible, has a new look and feel, and has been designed to improve readability. Document windows such as code editor and design view windows can now float outside the main IDE window and can be displayed on multiple monitors.

For C++ developers, IntelliSense and code-browsing features now scale to projects with millions of lines of code without compromising on performance. The build system and project system have migrated to MSBuild and offer better customizability and extensibility. Finally, code-generation improvements in the back-end of the Visual C++ compiler enable better performance and code quality.

In this article, I'll take a closer look at these core enhancements to Visual Studio 2010 and explain how these language features, updated libraries and tools can benefit C++ developers.

C++0x Core Language Features
Visual Studio 2010 gives developers powerful new core language features from the upcoming C++0x standard. The Visual C++ compiler in Visual Studio 2010 has enabled six C++0x core language features: lambda expressions, auto keywords, rvalue references, static_assert, nullptr and decltype.

Lambdas are a core language feature that have lightweight natural syntax to define function objects where they're used, and these expressions have no performance overhead. Function objects are a very powerful way to customize the behavior of Standard Template Library (STL) algorithms and can encapsulate both code and data (unlike plain functions). In C++ development, lambda expressions implicitly define and construct unnamed function objects.

Auto keyword is now used to automatically determine the type of a variable from its initializer. Auto reduces verbosity and helps important code stand out; it also helps make code more generic by allowing you to write templates without having to worry about the types of intermediate expressions.

C++0x has introduced a new kind of reference type called rvalue references. Rvalue references help solve the problem of unnecessary copying and enable perfect forwarding. This reference type enables move semantics. When the right-hand side of an assignment is an rvalue, then the left-hand side object can steal resources from the right-hand side object rather than performing a separate allocation. Perfect forwarding allows you to write a single function template that takes N arbitrary arguments and forwards them transparently to another arbitrary function. For a more detailed discussion on rvalue references, check out the MSDN documentation on the topic here.

Static_assert allows you to test assertions during compile time, rather than at execution time. Static assertions enable you to trigger compiler errors with custom error messages that are easy to read; they're especially useful for validating template parameters.

Nullptr keyword has been introduced in this release to help developers avoid difficult-to-diagnose failures in perfect forwarding functions. Nullptr is a constant, which is convertible to any pointer type, but no other type (for example, int or char). In addition to being used in the perfect forwarding functions, this new nullptr can be used anywhere the macro NULL was used as a null pointer.

Decltype is a language feature that allows the compiler to infer the return type of a function based on an arbitrary expression and makes perfect forwarding more generic. In past versions, for two arbitrary types T1 and T2 there was no way to deduce the type of an expression that used these two types. The decltype allows you to state things like an expression that has template arguments, such as: sum<T1, T2>() has the type of T1+T2.

Standard Library Improvements
Substantial portions of the standard C++ library have been rewritten in Visual Studio 2010 to take advantage of the new C++0x language features and increase performance.

In particular, adoption of rvalue references has yielded many benefits. Types such as vector and list now have move constructors and move assignment operators of their own. For example, vector reallocations exploit move semantics by picking up move constructors.

Therefore, if your types have move constructors and move assignment operators, the library will recognize that information automatically. The C++0x function template make_shared<T>() has been added to the standard library. You can now make a shared pointer to an object at the same time that you're constructing the object:

auto sp = make_shared<T>(args);

This provides you with a more convenient, robust and efficient way to use a shared pointer.

The standard library now provides you with a new pointer type unique_ptr that can be used in place of auto_ptr and allows you to implement strict ownership semantics without affecting safety. This release includes a number of new algorithms proposed in various C++0x papers, such as min/max element, iota and is_sorted.

Additionally, a small set of conversion libraries has been included in the standard library, which will allow developers to do conversions such as UTF-8 to UTF-16 with ease.

Also, many of the TR1 features that existed in namespace std::tr1 in the previous release, such as shared_ptr and regex, have now been made part of the standard library and have been moved under namespace std.

New Concurrency Runtime and Libraries
Visual Studio 2010 introduces the Parallel Computing Platform, which helps you write high-performance parallel code quickly while avoiding subtle concurrency bugs. This lets you avoid some of the classic problems faced with concurrency.

The Parallel Computing Platform has four major parts: the Concurrency Runtime (ConcRT), the Parallel Patterns Library (PPL), the Asynchronous Agents Library, and parallel debugging and profiling tools.

The concepts of tasks, the PPL and the Asynchronous Agents Library provide you with a programming model to approach writing parallel code more elegantly. These libraries are based on the new ConcRT, which is included within the Visual C++ runtime. The mapping between tasks and execution threads -- and ensuring that all the cores are optimally utilized -- is managed by ConcRT, which is the lowest software layer that talks to the operating system and arbitrates between multiple concurrent components competing for resources.

Any computation that can be decomposed into sub-computations can be implemented using tasks. For example, sorting two halves of an array can be done by two different tasks concurrently. Even the simple concept of threads takes you away from your problem domain by making you think about the hardware, OS and critical sections. Task is an abstraction that's much closer to your problem domain. Tasks are first-class concepts in parallel algorithms, classes and containers included in PPL.

Additionally, the Asynchronous Agents Library gives you a dataflow-based programming model where computations are dependent on the required data becoming available. The library is based on the concepts of agents, message blocks and message-passing functions. An agent is a component of an application that does certain computations and communicates asynchronously with other agents to solve bigger computation problems. This communication between agents is achieved via the message-passing functions using message blocks to help avoid issues that arise from the use of shared memory in concurrent applications.

Support for parallel debugging and profiling in Visual Studio 2010 makes it easier to debug concurrency issues. The debugger includes new tool windows to visualize the state of all tasks in an application. The concurrency profiler tool allows you to visualize the behavior of parallel applications.

IntelliSense and Design-Time Productivity
A brand new IntelliSense and browsing infrastructure is included in Visual Studio 2010. In addition to helping with scale and responsiveness on projects with large code bases, the infrastructure improvements have enabled building some fresh design-time productivity features.

IntelliSense features such as live error reporting and quick info tooltips are based upon a new compiler front-end. It parses the full translation unit to provide you with rich and accurate information about code semantics, even while the code files are being modified.

All the code-browsing features, like class view and class hierarchy, now use the source code information stored in a SQL database that enables indexing and has a fixed memory footprint. Unlike previous releases, the Visual Studio 2010 IDE is always responsive and you no longer have to wait while compilation units get reparsed when changing a header file.

The IntelliSense live error reporting is a new feature added in this release. The editor displays compiler-quality syntax and semantic errors during browsing and editing of code, without doing a build. A wavy underline (squiggle) is displayed at the location of the error, and the tool tip shows the error message, as shown in Figure 1. The error list window also shows this error, as well as the Intelli-Sense errors from elsewhere in the current compilation unit.


[Click on image for larger view.]
Figure 1. In Visual Studio 2010, live error reporting shows loss of IntelliSense at the location of the error and with a tool tip message.

Another new feature to increase your productivity with file or symbol search is Navigate To, under the Edit menu or using the shortcut "Ctrl+comma." This feature gives you real-time search results (based on substrings as you type) matching your input strings across any project. It also works for C# and Visual Basic projects, and is extensible.

Developers also get Auto Complete help for include statements in Visual Studio 2010. A list of relevant include files is displayed in a drop-down while typing #include, and the list will refine as you type and help you add the right include files with less typing. Call

Hierarchy -- an improved version of Call Browser -- provides you with the calls to and calls from trees for any function in the same window. Inactive code now retains the semantic information by maintaining colorization, instead of becoming gray.

Note that while all the code-browsing features are available for both pure C++ and C++/CLI, IntelliSense-related features like live error reporting and Quick Info will not be available for C++/CLI in the final release of Visual Studio 2010. We're working on adding full IntelliSense support for C++/CLI in the future.

Build and Project Systems
Visual Studio 2010 also offers substantial improvements in the build system and the project system for C++ projects.

The most important change is that MSBuild is now used to build C++ projects. MSBuild is an extensible, XML-based build orchestration engine that has been used for C# and Visual Basic projects in previous versions of Visual Studio. MSBuild is now the common Microsoft build system for all languages. It can be used both in the build lab as well as on individual developer machines.

C++ build processes are now defined in terms of MSBuild target and task files and provide you a greater degree of customizability, control and transparency.

The C++ project type now has a new extension: .VCXPROJ.

Visual Studio will automatically upgrade old .VCPROJ files and solutions to the new format. There's also a command-line tool, vcupgrade.exe, to upgrade single projects from the command line.

In the past, you only had the option of using the toolset -- the compiler and libraries -- that came with that particular version of Visual Studio. Visual Studio 2010 solves that problem by allowing you to target a different version of the toolset -- for example, the Visual C++ 9.0 version of compiler and libraries from Visual Studio 2010 -- while being able to take advantage of all the new productivity features. This functionality is known as native multi-targeting.

You can also extend the default build system by adding a tool or build step. This is especially useful for creators of libraries and tools. The Project system, which sits on top of the Build system, leverages the extensibility provided to it by MSBuild. It allows you to surface your customizations in the project system UI, enabling developers to configure those customizations in the same way that they can configure C++ compiler settings in the property pages. You can also configure a project system to use your own platform, similar to the existing x86 or x64 platforms, or your own debugger.

MSBuild provides better diagnostic information to make it easier for you to debug build problems. This also makes incremental builds more reliable. Plus, you can create build systems that are more closely tied to source control and build lab, and are less dependent on the developer machine configuration.

Faster Compilation and Better Performance
In addition to the design-time experience improvements described so far, Visual Studio 2010 also improves the compilation speed, quality and performance for applications built with the Visual C++ compiler. The compiler back-end has added multiple code-generation enhancements to bring these improvements.

The performance of certain applications depends on the working set. The code size for the x64 architecture has been reduced in the range of 3 percent to 10 percent by making multiple optimizations in this release, which has resulted in a performance improvement for such applications.

Single Instruction Multiple Data code generation -- which is important for game, audio, video and graphics developers -- has been optimized for better performance. Breaking false dependencies, vectorization of constant vector initializations, and better allocation of XMM registers to remove redundant loads, stores and moves are all improvements that have been introduced in this release.

For improved performance, applications should be built using Link Time Code Generation (LTCG) and Profile Guided Optimization (PGO). Compilation with LTCG usually takes longer than non-LTCG compilation, especially in large applications. In Visual Studio 2010 the LTCG compilation has been improved by up to 30 percent.

PGO instrumentation runs have been made faster by adding support for no-lock versions of instrumented binaries. There's also a new POGO option, PogoSafeMode, which enables you to specify whether to use safe mode or fast mode when you optimize an application. Fast mode is the default behavior. Safe mode is thread-safe, but slower than fast mode.

A dedicated thread to write .PDB files has been introduced in this release, so you'll see link time improvements when you use the /DEBUG switch. Also, the quality of compiler-generated code has been improved. There's now full support for Advanced Vector Extensions (AVX) that are very important for floating-point-intensive applications in AMD and Intel processors via intrinsic and /arch:AVX options. Floating point computation is more precise with /fp:fast option.

Build Great Applications on Windows 7
Windows 7 has introduced a number of exciting technologies and features. You can take advantage of innovations like Direct3D 11, DirectWrite, Direct2D and Windows Web Service APIs by using the SDK headers and libraries available in Visual Studio 2010.

In addition to making all the Windows APIs available to developers, this release of Visual Studio gives you access to Windows 7 functionality through updated MFC libraries. Your existing MFC applications will light up on Windows 7 just by recompiling, and your new applications will be able to take full advantage of the new Windows 7 features. For example, your application's integration with Windows Explorer can now be better optimized by making use of file handlers for preview, thumbnails and search. Taking advantage of previews, thumbnails and the search indexer provided by Windows is as easy as selecting these options in the MFC Application Wizard. Your application will be able to show rich thumbnails and previews in Windows Explorer. MFC provides this capability without you having to write a single additional line of code.

One of the most noticeable UI changes in Windows 7 is the new Taskbar. MFC allows developers to quickly take advantage of features such as jump lists, tabbed thumbnails, thumbnail preview, progress bar and icon overlay, as shown in Figure 2.


[Click on image for larger view.]
Figure 2. The updated MFC library allows developers to take advantage of thumbnail previews and tabbed thumbnails in Windows 7 for a tabbed MDI MFC application.

The Ribbon UI now has a Windows 7-style ribbon as well. MFC enables applications to become multi-touch-aware and calls appropriate messages for you to handle when the various touch events occur. Your application can register to inform MFC that it's interested in touch and gesture events, and MFC will take care of appropriately routing those events for your application. MFC also makes applications high-DPI aware by default. Therefore, your applications will adapt to high-DPI screens and won't look pixilated or fuzzy. MFC internally scales and changes fonts to make sure the UI continues to look sharp on high-DPI displays.

In addition to some of the new Windows 7 features, Visual Studio 2010 supports features that have existed since Windows Vista but were not included in previous releases of MFC. For example, Restart Manager is a very useful feature introduced in Vista that enables an application to perform an application save before terminating, and can re-invoke the application and restore its state from before shutdown. You can now take full advantage of Restart Manager in your MFC application to handle crashes and restarts more elegantly. Another addition is the Task Dialog, which is an improved version of message box. MFC now has a wrapper for Task Dialog.

Functionality has been added in MFC, and this release also makes it easier to work with the library in the IDE. One of the most commonly requested features, MFC Class Wizard, has been brought back from Visual Studio 6.0 and improved. You can easily add classes and event handlers in your application using MFC Class Wizard.

Additionally, this release has introduced a rich Ribbon designer while also making the Ribbon itself an XML resource rather than code, as it was in the previous release.


[Click on image for larger view.]
Figure 3. The popular MFC Class Wizard -- which lets developers visually add classes, messages and variables to MFC projects -- is back in Visual Studio 2010.

Wrapping Up
Visual Studio 2010 is a major release in the evolution of Visual C++. Whether it's the improved productivity with large code bases, the introduction of C++0x language features, support for parallel coding or the opportunity to write modern Windows 7 applications, Visual Studio 2010 has a lot to offer a C++ developer.

For further discussion on different features, please refer to the MSDN documentation and to the Visual C++ Team's blog at blogs.msdn.com/vcblog, which was also used as the basis for some of the sections in this article. A more detailed version of this article will also be published in the April issue of MSDN magazine.

comments powered by Disqus

Reader Comments:

Sat, Feb 15, 2014

http://w DOT ww.amendmentinsurance.com http://www.lehighmbawomen.com/ DOT http://m DOT usicflora.com http://www.insurecaronline.com/ DOT http://w DOT ww.hairrepaironline.net http://w DOT ww.leadinglifeinsurancebrands.com

Tue, Feb 4, 2014

http://www.yeeshkabob.com/ DOT http://w DOT ww.ensureyourself.com http://www.racheltatum.com/ DOT http://www.menshealthprice.com/ DOT http://www.anrinternplace.com/ DOT http://w DOT ww.genmedica.net

Mon, Jan 27, 2014

http://clamorousfall.com/f DOT orex-online.html http://w DOT ww.yourlifepolicies.com http://y DOT ankeegold-anovel.com http://w DOT ww.cheaphealthinsurancequotes.net http://b DOT aapalsa2013.com

Fri, Jan 24, 2014

http://w DOT ww.protectionrates.net http://w DOT ww.medinsurers.com http://w DOT ww.gettopedmeds.com http://www.buyfirstmedication.com/ DOT http://w DOT ww.cheapinsurancemate.com http://w DOT ww.lifeinsuranceshopping.net

Mon, Jan 20, 2014

http://w DOT ww.medinsurers.com http://w DOT ww.cheapairflights4you.com http://w DOT ww.businessinsurrates.com http://w DOT ww.mylifeinsuranceguide.net http://w DOT ww.healthinsurancebible.com http://w DOT ww.casinosspot.com http://w DOT ww.mylifeinsuranceplace.com

Fri, Jan 17, 2014 Karcy http://w DOT ww.treatbacterialinfections.com http://w DOT ww.carinsursite.com http://w DOT ww.casinosspot.com http://w DOT ww.getcheaphealthinsurance.net

http://w DOT ww.treatbacterialinfections.com http://w DOT ww.carinsursite.com http://w DOT ww.casinosspot.com http://w DOT ww.getcheaphealthinsurance.net http://www.mybestinsurancequotes.net/ DOT http://w DOT ww.starcraft2-wiki.com

Sun, Nov 10, 2013 Medford buying car insurance online

http://www.carinsurquote.net/ DOT

Wed, Sep 18, 2013 Sewana miles credit card

http://www.travelrewardscards.net/ DOT

Sun, Feb 26, 2012 Baffled

Visual Studio gets worse (and slower!!!) with every version. They shovel more and more crap and and do stuff no one cares about like 'oooh pretty new colors for the GUI' but they still haven't given us a fast incremental linker. If Microsoft don't get their act together they will find people drifting from Windows to other platforms. Look at the other useless crap they change, like getting rid of project directories so we can use this convoluted property sheets when we used to by able to just type stuff in. Honestly! Where does Microsoft get these people from?

Fri, May 13, 2011

Cris: Quote: "I went to Qt and it like I moved 50 years ahead in time" end Quote. I noticed you use "dumb" and "stupid" in your attack on MFC. That coupled with your "ability" to see into the future must make you a special kind of person. Yes I think we mortals know what kind of person you are!

Thu, Mar 3, 2011 Joseph M. Newcomer Pittsburgh

The problem is that Microsoft keeps thinking that a program editor is technology, and everyone knows that program editors are a religion.

We would be better off if, instead of wasting time "improving" the editor, they provided interfaces for third-party editor developers to use, so we could use our favorite editors

Thu, Feb 17, 2011 cris

Mfc is a dumb, old, deprecated library, having mostly the same features as in mid 90s No real oop/design in the class library, bad resource system, stupid callbacks/winapi system, handles and low level stuff. I went to Qt and it like I moved 50 years ahead in time (not to mention that it's cross platform and still c++). No way back I guess...

Thu, Jan 20, 2011 disgruntled

"Most people would never need to use it" C++/CLI, unless they would like to use some neat features like drag and drop on a DataGridView. Microsoft's toolbox for C++ looks the same as it did in 2000. This appears to me to be an attempt at forcing adoption of Microsoft's C# language that is directly tied to the .NET framework so they can manage web based data.

Mon, Nov 8, 2010 Md.Roman Bangladesh

get tomch help...Thanks

Fri, Oct 8, 2010 Steven

Atoo, C++/CLI with intellisense is still garbage. They are not trying to destroy C++, they are doing a very good job of implementing the upcoming standard ahead of time. Also, VB and C# are not "sluggish, interpreted, and sick", their performance when programmed appropriately is entirely fit for their purpose.

Wed, Sep 29, 2010 Stu Denver

This is a pretty clear sign from MS that C++/CLI devs are second-class citizens these days. Intellisense used to work fine for C++/CLI in VS2008--that's what's so frustrating to a lot of people... it's like we had the carpet pulled out from under us. We have a big, unmanaged API, and we use a tremendous amount of wrapper code written in C++/CLI, so we're kind of screwed. It's a slap in the face after we shelled out $12,000 for our MSDN subscription w/ VS Ultimate. So I'm interpreting VS2010 as a sign that devs should run, not walk, away from C++/CLI--it's got one foot in the grave. Here we are, 5 months after release, and there's still no word on when the support is coming out, and there have been no further reassurances from MS... all we have are the vague promises from May. They're clearly more interested in shiny bells and whistles for the drag-and-drool devs ("ooh, hardware-accelerated IDE!") than supporting their existing systems-level customers. So overall, I think VS2010 is a good product if you're writing line-of-business apps in C#... but if you're an ISV doing low-level development then there's no getting around the fact that Microsoft really doesn't care about you--they change their low-level platforms and tools to suit their needs, not yours.

Fri, Sep 24, 2010 anon

Please re-read the article. Of course intellisense works for C++ in VS2010! It does not work for C++/CLI - C++/CLI IS NOT C++!!! C++/CLI is what used to be called "managed C++" - it is only meant to be used as a glue language for interfacing with managed languages (such as C#) from C++. Most people will never need to use it.

Sat, Sep 4, 2010 HK

This is the first time MS is taking a feature away in a new version. That is missing IntelliSense in VS C++ 2010. I guess they do not care anymore.

Sun, Aug 15, 2010 drubi palestine

glad microsoft is back to reality supporting andimproving vc++ something is missing that is ability to utilise web apps into desktop apps, like qt from nokia

Thu, Aug 5, 2010 PS

On the positive side, I would love the new Class Wizard, if it wasn't so TERRIBLY slow. On my fast, multi-core PC, it takes at least 30 seconds to show after I launch it from a dialog. If I do the same from VC6 it takes a few milliseconds!! It is also slightly buggy... I also find the editor sluggish and distracting. It also flashes WAY TO MUCH. All in all, VC6 is super zippy, VS2010 is EXTREMELY, repeat EXTREAMLY slow. I'm not switching yet, but hoping that MS will increase the speed by at LEAST 100 TIMES. Using WPF for a developpment tool is a JOKE! But we're getting there, aren't we MS? After 8+ years, there's at last a pretty decent Class Wizard.

Wed, Jul 7, 2010 Rodrigo Brazil

I must say I strongly dislike this WPF interface. It's sluggish and slow, and also the color schemes are horrible. I'm keeping my Visual Studio 2008.

Tue, Jun 29, 2010 antilove

microsoft want to destroy C++ ? what kind of drugs do you take ? willing to share?

Thu, May 13, 2010 Ed

I really dislike the new UI design of VS2010. The contrast of UI elements gives me eyestrain and headaches. And the text rendering is bugged... each time I open a file, it's blurred at first and after 1-2 secs gets redrawn correctly. It happens on any newly viewed text. Terrible WPF workaround, I say... why the hell did they use WPF anyway? It's such a performance waste for a C++ developer.

Sat, May 1, 2010 MS_A_Joke

MS is a big joke, they don't make IntellSense to work with the latest Visual Studio, 2010, WTF!? Everything they do is about money! MS's capitalism sucks!

Tue, Apr 20, 2010 Ventura

Confirm: Is C++ and C++0x compatible with new Windows7? Also, about how much $$ and where can one get new C++ / C++0x and compiler? Many thanks!!!

Mon, Apr 19, 2010 Markus

Sorry but what is your point except ranting, Atoo? There is no word that .NET will be forced upon you while using Visual C++. You will still be able to use native C++. MFC as well as managed C++ are optional. This article is about language/library improvements - native C++ library and compiler improvements ... Seems you didn't get some bits right

Wed, Apr 14, 2010 Atoo

This release is in fact Microsoft's attempt trying to destroy C++. They want to force every one to use the sluggish, interpreted, and sick C# and VB.Net. It does not work that way. Visual C++/CLI without intellisense is garbage. I would rather stick to my Visual C++ 2008 or move to other C++ compilers and IDEs.

Add Your Comments Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above

.NET Insight

Sign up for our newsletter.

I agree to this site's Privacy Policy.