Algorithms, Blockchain and Cloud

The C++ Static Code Analyser by Visual Studio


Microsoft’s Visual Studio has provided a C++ static code analyser. It is available at navigation menu – Analyzer – Config/Run Code Analyser.

analyze-code-analysis-vs The C++ Static Code Analyser by Visual Studio c / c++ static code analyser Visual Studio

analyze-code-analysis-vs

Configure the Static Code Analyser Rules

By default, the ruleset for static code analyser (C++) is ‘Microsoft Native Recommended Rules’ but you can always try different rulesets to see if it gives you more analysis (different levels of details).

configure-code-rules-set

Run the Static Code Analyser

You can manually run the static code analyser on projects/solutions by go to navigation menu – analyser – Run Code Analyser, also you can enable it at each build:

enable-code-analysis-on-build

Sample Analysis Results

The following gives a detailed analysis on the sample code.

Sample Static Code Analysis Results from Visual Studio C++

However, sometimes the static code analyser does not thoroughly understand the code, instead, it just warns you for potential coding pitfalls e.g. array out of bound access. In the above example, the length of the array is never one and the variable t is gaureente to be smaller than the variable maxlen. Therefore, the warning is not 100% correct but it at least hints you to review your code.

–EOF (The Ultimate Computing & Technology Blog) —

399 words
Last Post: Cloudflare Offers Dedicated SSL Certificates
Next Post: How to Get Minimum Moves to Equal Array Elements?

The Permanent URL is: The C++ Static Code Analyser by Visual Studio (AMP Version)

Exit mobile version