Is there a gcc flag to catch integer truncation?

前端 未结 2 614
时光说笑
时光说笑 2021-01-18 10:51

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 -Wex

2条回答
  •  借酒劲吻你
    2021-01-18 11:28

    Yes, use the -Wfloat-conversion option:

    -Wfloat-conversion

    Warn for implicit conversions that reduce the precision of a real value. This includes conversions from real to integer, and from higher precision real to lower precision real values. This option is also enabled by -Wconversion.

提交回复
热议问题