Why compiler allows narrowing conversions

前端 未结 3 1181
醉梦人生
醉梦人生 2020-12-16 05:30

Can anyone please explain to me, why the compiler allows initialize variables of built-in type if the initializer might lead to the loss of information?

For example

3条回答
  •  生来不讨喜
    2020-12-16 06:02

    This issue has been coming up lately. With gcc-4.7 a command line switch turns on the required behaviour:

    g++ -Werror=narrowing ...
    

提交回复
热议问题