Can I make GCC warn on passing too-wide types to functions?

后端 未结 2 1630
南方客
南方客 2020-11-30 12:59

Following is some obviously-defective code for which I think the compiler should emit a diagnostic. But neither gcc nor g++ does, even with all th

2条回答
  •  没有蜡笔的小新
    2020-11-30 13:06

    Use -Wconversion -- the problem is an implicit cast (conversion) from long x to short when the function f(short x) is called [not printf], and -Wconversion will say something like "cast from long to short may alter value".

    ..

    Edit: just saw your note. -Wconversion results in a warning for me, using g++ 4.3.2 on Linux... (4.3.2-1 on Debian)

提交回复
热议问题