是否有一个gcc标志赶上整数截断? [英] Is there a gcc flag to catch integer truncation?

查看:90
本文介绍了是否有一个gcc标志赶上整数截断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个 GCC 标志信号警告/错误,当我试图把一个双击值成 INT 变量?我目前有 -Wall -Wextra -Werror 设置,但我还是当我(例如)通过没有得到警告说,双击 INT 参数,即使我失去的信息。

Is there a gcc flag to signal a warning/error when I try to put a double value into an int variable? I currently have -Wall -Wextra -Werror set but I still don't get warned when I (for instance) pass a double to an int parameter, even though I'm losing information.

推荐答案

您可以使用的 -Wconversion 选项。从GCC手册的(重点煤矿)的:

对于警告可能改变的值隐式转换。 这包括
  实数和整数
,之间的转换像ABS(X)当x为双;
  之间的转换符号和无符号,就像usigned UI = -1;和
  转换到更小的类型,如sqrtf(M_PI)。不要为警告
  显式转换像ABS((int)的x)和UI =(无符号)-1,或者如果
  值不被转换象在无水(2.0)的变化。警告
  约之间的转换符号和无符号整数,可以被禁用
  通过使用-Wno符号转换。

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.

这是uptill GCC 4.8.2的状态,而从GCC 4.9.0,也可以使用的 -Wfloat转换 以相同的。

This is the state uptill GCC 4.8.2, while from GCC 4.9.0 you may also use -Wfloat-conversion for the same.

这篇关于是否有一个gcc标志赶上整数截断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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