当前位置: 技术问答>linux和unix
gcc 编译参数求教
来源: 互联网 发布时间:2016-09-17
本文导语: // a.c int main(int argc, char **argv) { double d = -1.5; unsigned int i; j = i; // 这里有强制类型转换,我希望能打印出警告 return j; } 不知道打印强制类型转换需要加什...
// a.c
int main(int argc, char **argv) {
double d = -1.5;
unsigned int i;
j = i; // 这里有强制类型转换,我希望能打印出警告
return j;
}
不知道打印强制类型转换需要加什么参数
我用gcc -Wall -W a.c 也不会打印相应警告
int main(int argc, char **argv) {
double d = -1.5;
unsigned int i;
j = i; // 这里有强制类型转换,我希望能打印出警告
return j;
}
不知道打印强制类型转换需要加什么参数
我用gcc -Wall -W a.c 也不会打印相应警告
|
gcc -Wconversion a.c
$ man gcc
......
-Wconversion
Warn for implicit conversions that may alter a value. This includes conversions
between real and integer, like "abs (x)" when "x" is "double"; conversions between
signed and unsigned, like "unsigned ui = -1"; and conversions to smaller types, like
"sqrtf (M_PI)". Do not warn for explicit casts like "abs ((int) x)" and "ui =
(unsigned) -1", or if the value is not changed by the conversion like in "abs
(2.0)". Warnings about conversions between signed and unsigned integers can be
disabled by using -Wno-sign-conversion.
$ man gcc
......
-Wconversion
Warn for implicit conversions that may alter a value. This includes conversions
between real and integer, like "abs (x)" when "x" is "double"; conversions between
signed and unsigned, like "unsigned ui = -1"; and conversions to smaller types, like
"sqrtf (M_PI)". Do not warn for explicit casts like "abs ((int) x)" and "ui =
(unsigned) -1", or if the value is not changed by the conversion like in "abs
(2.0)". Warnings about conversions between signed and unsigned integers can be
disabled by using -Wno-sign-conversion.
|
j在哪儿定义了?
|
先-Wall,不会提示的话,再试一下楼上说的。
|
gcc -Wconversion a.c