g ++ - 不会警告double-> int cast [英] g++ -Wall not warning about double-> int cast
本文介绍了g ++ - 不会警告double-> int cast的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在以下代码段中不会生成警告。 g ++ 4.4.3 -Wall -pedantic
In the following snippet no warnings are produced. g++4.4.3 -Wall -pedantic
//f is
void f(int );
f(3.14);
double d = 3.14;
int i = d+2;
我有一个强烈的回忆,这是一个警告, 。是否已删除或是我的记忆对我使用技巧?
I have a strong recollection of this being a warning, something along the lines of "Possible loss of precision". Was it removed or is my memory playing tricks on me?
如何将这变成一个警告在g ++?我发现这是一个有用的警告,或者是一个坏主意?
How can i turn this into a warning in g++? I find this a useful warning, or is it a bad idea?
我在 http://gcc.gnu.org/onlinedocs/gcc-4.4.5/gcc/Warning-Options.html
推荐答案
$ gcc -Wconversion test.c
test.c: In function ‘main’:
test.c:3: warning: conversion to ‘int’ from ‘double’ may alter its value
这篇关于g ++ - 不会警告double-> int cast的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文