分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow
![](https://i-blog.csdnimg.cn/blog_migrate/007e6a9537a5eebfbea51d9890cb4518.png)
Cppcheck是一个C/C++代码分析工具,只检测那些编译器通常无法检测到的bug类型。
官方上建议让编译器提供尽量多的警告提示:
1.使用Visual C++的话,应使用警告等级4
1.使用Visual C++的话,应使用警告等级4
2.使用GCC的话,参看
Warning options - using GCC
当前版本:1.54 for windows
安装界面如下:
![](https://i-blog.csdnimg.cn/blog_migrate/5d3a36bb81428b426b8e5b94237c26d3.png)
安装完后,双击cppcheckgui.exe启动其GUI程序:
![](https://i-blog.csdnimg.cn/blog_migrate/0fb52a3b9e7829453e67de216aa70922.png)
工具栏第一个按钮
可以添加检测的目录,但是这里 不支持中文路径。测试官方的例子,新建一个文件file1.c,内容如下:
![](https://i-blog.csdnimg.cn/blog_migrate/ce3c17bfed38b6fab654639e31dd50d7.png)
int main()
{
char a[ 10];
a[ 10] = 0;
return 0;
}
用此工具进行检测,结果如下图所示:
{
char a[ 10];
a[ 10] = 0;
return 0;
}
![](https://i-blog.csdnimg.cn/blog_migrate/bf148b62ac2c2b335a2038582ab88d96.png)
一下子就分析出了其中的警告和错误。用命令行检测的话,可以支持中文路径,效果如下图所示:
![](https://i-blog.csdnimg.cn/blog_migrate/897bf335d30a53cdea4609ad949b1a4d.png)
命令行方式,默认只显示错误的信息,使用--enable打开其他提示信息,如下:
cppcheck.exe --enable =all "E:\项目\测试"
在Visual Studio下使用的话,步骤如下:
1.在Visual Studio菜单栏"工具"→"外部工具",点击"添加",内容如下:
标题:Cppcheck
命令:D :\Program Files\Cppcheck\cppcheck.exe
参数: --enable =all -- template =vs $(SolutionDir)
勾选 "使用输出窗口"
2.使用时,点击"工具"→"Cppcheck"即可,如下图所示:
命令:D :\Program Files\Cppcheck\cppcheck.exe
参数: --enable =all -- template =vs $(SolutionDir)
勾选 "使用输出窗口"
![](https://i-blog.csdnimg.cn/blog_migrate/ca4c4a5a83deb5f57924f08c82d52110.png)
双击提示内容,即可定位到所在行。
附录:
1.cppcheck命令行参数
Syntax:
If a directory is given instead of a filename, *.cpp, *.cxx, *.cc, *.c++, *.c, *.tpp, and *.txx files are checked recursively from the given directory.
cppcheck [OPTIONS] [files or paths]
--append=<file> | This allows you to provide information about functions by providing an implementation for them. |
--check-config | Check cppcheck configuration. The normal code analysis is disabled by this flag. |
-D<ID> | By default Cppcheck checks all configurations. Use -D to limit the checking to a particular configuration. Example: '-DDEBUG=1 -D__cplusplus'. |
-U<ID> | By default Cppcheck checks all configurations. Use -U to explicitly hide certain #ifdef <ID> |