如何在 Visual Studio 2005 中获得 printf 警告? [英] How to get printf warnings in Visual Studio 2005?

查看:73
本文介绍了如何在 Visual Studio 2005 中获得 printf 警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当给 printf() 提供错误数量的参数时:

When providing the wrong number of arguments to printf():

printf("%s", "foo", "bar");

或者当提供错误类型的参数时:

or when by providing arguments of the wrong type:

printf("%d", "foo");

gcc 能够警告这些错误:

gcc is able to warn about these mistakes:

$ gcc -Wformat printf_too_many_arguments.c
printf_warnings.c: In function `main':
printf_warnings.c:5: warning: too many arguments for format
printf_warnings.c:5: warning: too many arguments for format

$ gcc -Wformat printf_argument_of_wrong_type.c
printf_warnings.c: In function `main':
printf_warnings.c:5: warning: format `%d' expects type `int', but argument 2 has type `char *'
printf_warnings.c:5: warning: format `%d' expects type `int', but argument 2 has type `char *'

如何使用 Visual Studio 2005 获得此类警告?

How to get such warnings with Visual Studio 2005?

--戴夫

推荐答案

我使用 cppcheck (http://cppcheck.sourceforge.net/) 使用 Visual Studio 2005 时,它会检测提供给 printf/wprintf 的参数数量与所需参数数量之间的不匹配.

I use cppcheck (http://cppcheck.sourceforge.net/) when working with Visual Studio 2005 which detects mismatches between the number of parameters provided to printf/wprintf and the number of parameters required.

不幸的是,它没有检查类型是否匹配,但这只是一个开始.

Unfortunately it doesn't check the types match, but it's a start.

这篇关于如何在 Visual Studio 2005 中获得 printf 警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆