【问题标题】:Difference between -Wconversion between gcc and g++ [duplicate]gcc和g ++之间的-Wconversion之间的区别[重复]
【发布时间】:2009-02-03 03:26:18
【问题描述】:

可能重复:
Can I make GCC warn on passing too-wide types to functions?

考虑以下测试程序:

static void func(int a)
{
}

int main()
{
    unsigned int b = 42;

    func(b);

    return 0;
}

用 gcc 编译:

lol@mac:~/projects$ gcc -Wconversion testit.c testit.c:在函数âmainâ中: testit.c:11:警告:由于原型,将 âfuncâ 的参数 1 传递为已签名 大声笑@mac:~/projects$

但是,在 g++ 中没有警告!:

lol@mac:~/projects$ g++ -Wconversion testit.c 大声笑@mac:~/projects$

这是什么原因,有什么办法在编译 C++ 代码时得到同样的警告?

【问题讨论】:

    标签: c++ c gcc g++


    【解决方案1】:

    来自the documentation-Wconversion

    除非显式启用 -Wsign-conversion,否则 C++ 中默认禁用有关有符号整数和无符号整数之间转换的警告。

    看来您还需要一个足够新的 GCC 版本。我有 4.0.1 版本,它无法识别 -Wsign-conversion

    【讨论】:

      猜你喜欢
      • 2010-12-03
      • 2015-02-06
      • 2011-05-31
      • 2014-08-16
      • 2011-04-08
      • 2012-11-24
      • 2013-06-05
      • 2021-09-29
      • 2020-05-27
      相关资源
      最近更新 更多