Visual Studio 2005 Integration


The incorporation of Code Analysis for C/C++ in Team System is a significant development. Until a few years ago, this feature was only available internally at Microsoft. Now, any C++ developer can benefit from the features of integrated static code analysis for maintaining better and more secure code.

Enabling and disabling C/C++ Code Analysis

Much of the work you will be doing with the C/C++ code analyzer will be within the Visual Studio 2005 test environment. You can access most of the Test windows by selecting Test image from book Windows from the main menu. To enable Code Analysis for C/C++, right-click on your C++ project in the Solutions Explorer and select Properties.

The project Property Pages window is shown in Figure 9-3.

  1. Expand the Configuration Properties node.

  2. Expand the Code Analysis node, and then click General.

  3. Under the Enable Code Analysis for C/C++ Option, select Yes (/analyze).

image from book
Figure 9-3

You can also enable Code Analysis for C/C++ another way:

  1. Right-click on your C/C++ project in the Solutions Explorer and select Properties.

  2. Expand the Configuration Properties node.

  3. Expand the C/C++ node.

  4. Select Advanced.

  5. Set Enable Code Analysis for C/C++ to Yes (/analyze), as shown in Figure 9-4.

    image from book
    Figure 9-4

To disable C/C++ Code Analysis, set any of the above options to No, rather than Yes (/analyze).

Note

Even though there are two ways of enabling C/C++ Code Analysis, you can enable or disable it in one spot, and it will automatically appear enabled or disabled in the other.

Setting warning levels in Visual Studio 2005

You can set warning level options using the Configuration Properties section of the Property Pages window. Follow these steps to change the warning levels from within the Visual Studio 2005 IDE:

  1. Right-click on your C++ project and select Properties.

  2. Expand Configuration Properties, then C/C++, and then General.

Using this window, you can set several options, including the following: Warning Level (/W<n>), Detect 64-bit Portability Issues (/Wp64), and Treat Warnings as Errors (/WX). The C/C++ General options are shown in Figure 9-5.

image from book
Figure 9-5

Note

You can also programmatically set warning levels using #pragma directives and as options when you compile your code with the command-line compiler. Both scenarios are covered in detail later in the chapter.

Viewing code analysis warnings and errors

From this point on, if you compile or build the project, all C/C++ code analysis–related warnings and errors will be logged and displayed on the Error List. Figure 9-6 shows how the warnings are represented in the Error List window.

image from book
Figure 9-6

One of the killer features from the integration of Code Analysis for C/C++ is code highlighting. If you click on any of the warnings, Visual Studio will automatically highlight in yellow the "defect path" (in other words, all the spots in your code) where errors may have occurred. As you can imagine, this greatly facilitates the debugging process.



Professional Visual Studio 2005 Team System
Professional Visual Studio 2005 Team System (Programmer to Programmer)
ISBN: 0764584367
EAN: 2147483647
Year: N/A
Pages: 220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net