g++ -Wall 没有关于双重警告->强制转换 [英] g++ -Wall not warning about double-> int cast

查看:24
本文介绍了g++ -Wall 没有关于双重警告->强制转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下代码段中,不会产生任何警告.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++ -Wall 没有关于双重警告->强制转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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