如何从g ++中丢失原型警告? [英] How do I get missing prototype warnings from g++?

查看:98
本文介绍了如何从g ++中丢失原型警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个使用g ++编译其代码的项目。我正在清理代码,我想确保所有函数都有原型,以确保正确处理const char *之类的东西。不幸的是,当我尝试指定-Wmissing-prototypes时,g ++抱怨:

I currently have a project that uses g++ to compile it's code. I'm in the process of cleaning up the code, and I'd like to ensure that all functions have prototypes, to ensure things like const char * are correctly handled. Unfortunately, g++ complains when I try to specify -Wmissing-prototypes:

g++ -Wmissing-prototypes -Wall -Werror -c foo.cpp
cc1plus: warning: command line option "-Wmissing-prototypes" is valid for Ada/C/ObjC but not for C++

有人可以告诉我:

1)为什么gcc无效?

2)是否可以打开此警告?

Can someone tell me:
1) Why does gcc this isn't valid? Is this a bug in gcc?
2) Is there a way to turn on this warning?

编辑:

这里有一个剪切示例:

cat > foo.cpp <<EOF
void myfunc(int arg1, int arg2)
{
    /* do stuff with arg1, arg2 */
}
EOF
g++ -Wmissing-prototypes -c foo.cpp  # complains about not valid
g++ -c foo.cpp                       # no warnings
# Compile in C mode, warning appears as expected:
g++ -x c -Wmissing-prototypes -c foo.cpp


推荐答案

您尝试-Wmissing-declaration吗?这似乎适用于g ++,并检测您描述的错误情况。我不确定他们将其添加到哪个版本中,但是它在4.3.3中对我有效。

Did you try -Wmissing-declarations? That seems to work for g++ and detect the error case you describe. I'm not sure which version they added it in, but it works for me in 4.3.3.

这篇关于如何从g ++中丢失原型警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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