Microsoft’s Visual Studio has provided a C++ static code analyser. It is available at navigation menu – Analyzer – Config/Run Code Analyser.
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).
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:
Sample Analysis Results
The following gives a detailed analysis on the sample code.
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) —
Last Post: Cloudflare Offers Dedicated SSL Certificates
Next Post: How to Get Minimum Moves to Equal Array Elements?