Identifying and Minimizing Noise

Code Analysis for C/C++ is a very verbose tool. Even with tiny bits of code, expect a lot of warning messages. These false positive errors are usually referred to as noise. Microsoft devised three primary design goals for the Code Analysis for C/C++ tool:

  • Extensibility and customization

  • Wide developer adoption

  • Reduction of noise

The wide adoption requirement is satisfied through the integration of C/C++ code analysis in Visual Studio 2005. To satisfy the extensibility and noise reduction requirements, Code Analysis for C/C++ offers many customization options to developers. We've examined two of these features earlier in the chapter:

  • Annotations

  • #pragma Support


Unlike other versions of PREfast, Team System's C/C++ static code analysis engine does not support custom filters.

Now that you have a firm grasp of the basics, let's look at a common source of noise and use customization techniques to reduce the levels in order to track down the serious errors!

Library header files are known to generate many warnings. These unintentional warnings can cause havoc in your debug process as you try to identify the serious problems in your code. Fortunately, #pragma directives can help you filter out the noise. Here is a practical example:

  1. When you compile your application, one of the libraries you are using (libtmp.h) is throwing the following error codes:

          warning C6031: return value ignored      warning C6059: Incorrect length parameter in call to getprice.

  2. The library header file is from a trusted source and shouldn't normally be generating warnings. You try to lower the sensitivity of the warning levels to level 4 during compile time using the following command:

          > cl.exe yourapp.cpp /analyze /W4 
  3. Unfortunately, some of the errors are persisting. In order to block these warnings, you decide to add a couple of #pragma directives in your library file. These directives effectively block the warnings appearing in the Test Explorer:

          #pragma warning (disable:6031)      #pragma warning (disable:6059)
  4. When you recompile the code, it runs normally with no warnings or errors.

Professional Visual Studio 2005 Team System
Professional Visual Studio 2005 Team System (Programmer to Programmer)
ISBN: 0764584367
EAN: 2147483647
Year: N/A
Pages: 220 © 2008-2017.
If you may any questions please contact us: