Use of static Code checking tool Cppcheck (can be integrated into VS and Qt creator separately)

Source: Internet
Author: User

Cppcheck is a static check tool for C/s code defects. Unlike the C + + compiler and other profiling Tools, Cppcheck only checks for bugs that are not checked by the compiler and does not check for syntax errors. The so-called static code check is the use of a tool to check whether the code we write is safe and robust, whether there is a hidden problem.

For example, inadvertently write this code:

[CPP]View PlainCopy
    1. int n = 10;
    2. char* buffer = new char[n];
    3. Buffer[n] = 0;

This is completely syntactically compliant, but the static code checker will prompt you to overflow here. In other words, it is a stricter compiler. There are Cppcheck, Pc-lint, and so on, which are widely used in the C + + static code checking tool. Pc-lint is the oldest and most powerful code-checking tool, but it is a paid-for software, and it is a bit of a hassle to configure.

Cppcheck is free open source software. It is also very convenient to use.

Download the latest cppcheck from http://cppcheck.sourceforge.net/.

How to use:

GUI mode: After installation, you can use the Cppcheck-gui inside to detect the code. The interface is as follows:

Second, the command line mode:

Third, integration into the IDE development environment using:

1. VS

Refer here (http://avitebskiy.blogspot.tw/2012/10/ poor-mans-visual-studio-cppcheck.html), you can easily embed cppcheck into VS, and then you can easily check a file and support error jumps.

    • Click the Add button
    • Set the Title, for example Cppcheck
    • Set Command to C:\Program Files (x86) \cppcheck\cppcheck.exe
    • Set Arguments to --quiet--verbose--template=vs $ (itempath)
    • Set Initial Directory to $ (itemdir)
    • Make sure use Output windows checkbox is enabled
    • Click on the Move up button repeatedly until your entry are at the top of the list, this would make it easier to Identify you new command as you can count on it being calledTools.externalcommand1
    • Click OK.

2. Qt Creator

In Qtcreator, click: Tools=>external=>config...=>add pop up the following dialog box:

Fill in the following parameters:

After setting up, you can use Cppcheck to check the code file under the specified directory: Tools=>external=>cppcheck start the check.

Reference article: http://www.cnblogs.com/lancidie/archive/2013/04/13/3019505.html

The following article is also very detailed: http://blog.csdn.net/akof1314/article/details/7477014

http://blog.csdn.net/e5max/article/details/11489137

Use of static Code checking tool Cppcheck (can be integrated into VS and Qt creator separately)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.