
PVS-Studio has a mode of operation that will help you identify errors and typos as soon as possible. The analyzer starts immediately after the files are compiled and if something is wrong, it will turn red with shame for your code. The feature is currently available only for users of Visual Studio 2010.
I repeatedly wrote, the earlier the error is detected, the lower the cost of fixing it. However, in this I am not original, and the authors of many books and articles repeated it and continue to repeat it. Take at least the same
S. McConnell . So I will not repeat.
Previous versions of the PVS-Studio analyzer had to be started manually or integrated into the nightly builds. The fact that in the morning you can see the log and correct some kind of mistake is unquestionably wonderful. But not perfect. It does not interfere during the day to plant a couple of small blunders and then search for each of them for 10 minutes. PVS-Studio will be of little help here. Running it only for modified files is inconvenient, and for the entire project it takes too long.
Fortunately, we are programmers and sensitive to the needs of our colleagues in the keyboard. In PVS-Studio 4.30, a new mode of incremental analysis has appeared. The check is now almost combined with the compilation step. The analyzer checks those files that are compiled by pressing the F7 button that we all love. Turning on this mode is not easy, but very simple. It is enough to check the box next to the “Incremental Analysis After Build” item in the PVS-Studio menu:
')

Now let's look at an example of how this works. Suppose I was very happy with the programming process, hurried and made a mistake in the array index:

The result of such an expression is always 'false'. But I do not notice. I write the code further and enjoy life. Then I press F7 with satisfaction from the work done, and the modified file is successfully compiled. And VS2010 does not issue any warnings. I calmly go to edit the next piece of code.
But when the compilation is finished, quietly, in the background, the PVS-Studio analyzer is launched and checks the modified files. In the background, it runs specifically to not interfere with the programmer. Static analysis takes longer to compile, and it makes no sense to make the programmer sigh heavily, looking at the progress dialogue. If everything is written correctly (both with you and with us ;-)), then the programmer will not notice the presence and operation of PVS-Studio at all.
However, there is an error. And after a while the analyzer will signal the presence of a suspicious code! It will turn red, and the programmer’s hand will reach for the required tab to find out the details:

And indeed, in the message you can read that the condition is always false:

As a result, the error will be corrected almost immediately after writing.
I invite you to try the new PVS-Studio mode. Download the trial version as usual
here . If after installation VS2010 starts to slow down, then reduce the appetites of PVS-Studio. By default, the analyzer uses all available processor cores during the scan. Accordingly, in the settings you can specify how many cores can be used.
I foresee several questions at once. Therefore, in advance prepared at the end of a small FAQ.
1) And why is the new mode supported only in VS2010?
Only in Visual Studio 2010 appeared API, which allows you to find out which files have been changed, and which ones depend on them. In other words, a mechanism appeared that allows you to select files for verification. A little more about it here [
1 ].
If you really like the new mode of operation, we will think about how to implement it for Visual Studio 2005/2008 users as well. However, I want to note that switching to Visual Studio 2010 is much easier than it might seem. You can choose the old compiler, but use the capabilities of the new environment. This is done using the Platform Toolset [
2 ].
2) Why not make a check at all on the fly and emphasize errors right away, like, for example, does IntelliSense do?
Firstly, such tight integration with Visual Studio is not available to us. To get it you need to be more friendly with Microsoft.
Secondly, it still does not work. Static analysis is rather complicated and, in order to identify some errors, it is necessary to collect information on a rather large code fragment. Since the code will be edited, it will almost always be impossible to parse it. I think every programmer has seen the C / C ++ compiler going crazy because of an accidental extra brace or an incorrect template. C / C ++ is not a language that can be analyzed very quickly.
3) And what if I don’t distinguish between green and red?
I agree with the remark. Perhaps in the next version we will not only change the color, but also write the text on the tab.
4) Why does this here and this not work?
This is a new feature and there is a high probability of some errors. We will be grateful if you tell us about the shortcomings and suggestions.
Feedback page .
5) If I do a Rebuild, will the analyzer then check the entire project?
Not. It does not make sense and for too long. The analyzer ignores the reassembly commands for solutions and projects. If you want to check a solution or a project, then, as before, the appropriate commands are available in the analyzer.
Additional resources:
- Pavel Eremeev. Using the PVS-Studio analyzer in the incremental build process in Microsoft Visual Studio 2010. http://www.viva64.com/ru/b/0101/
- Msdn How to: Modify the Target Framework and Platform Toolset. http://www.viva64.com/go.php?url=689