gcc 编译参数求教

hu_jiajun1979 2010-08-04 06:21:21
// a.c
int main(int argc, char **argv) {
double d = -1.5;
unsigned int i;

j = i; // 这里有强制类型转换,我希望能打印出警告

return j;
}


不知道打印强制类型转换需要加什么参数
我用gcc -Wall -W a.c 也不会打印相应警告

...全文
145 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hu_jiajun1979 2010-08-09
  • 打赏
  • 举报
回复
结贴了,虽然没有找到答案
hu_jiajun1979 2010-08-05
  • 打赏
  • 举报
回复
-Wconversion只能报出 unsigned ui = -1的错误
如果是 int i = -1;
unsigned ui = i;
这种写法,-Wconversion 报不出来的
mars199 2010-08-05
  • 打赏
  • 举报
回复
gcc -Wconversion a.c
Linux-Torvalds 2010-08-04
  • 打赏
  • 举报
回复
先-Wall,不会提示的话,再试一下楼上说的。
brookmill 2010-08-04
  • 打赏
  • 举报
回复
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.
hu_jiajun1979 2010-08-04
  • 打赏
  • 举报
回复
哦,代码错了
是i = d; // 这里有强制类型转换,我希望能打印出警告
return i;

就是希望报强制类型转换的警告
steptodream 2010-08-04
  • 打赏
  • 举报
回复
j在哪儿定义了?

23,120

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧