HOWTO:获取可能导致数据丢失的隐式类型转换的警告 [英] HOWTO: Get Warning on implicit type casts that may lead to data loss

查看:74
本文介绍了HOWTO:获取可能导致数据丢失的隐式类型转换的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在将C ++程序从32位系统迁移到64位系统。

的旧程序员使用了一些烦人的任务,比如将long

分配给int,这可能会导致数据丢失。


是否有可能让编译器(特别是GCC)在这种隐式类型转换上发出一些

警告?


或者你建议使用其他一些静态源代码分析工具?


提前致谢!

Hello everyone,

I''m migrating a C++ program from 32-bit systems to 64-bit systems. The
old programmers used some annoying assignments like assigning "long"
to "int", which may lead to data loss.

Is it possible to let the compiler (specifically, GCC) spew some
warnings on this kind of implicit type casts?

Or you suggest use some other static source codes analysis tools?

Thanks in advance!

推荐答案

在2007-11-11 15:39, el ************ @ gmail.com 写道:
On 2007-11-11 15:39, el************@gmail.com wrote:

大家好,


我正在从32迁移C ++程序-bit系统到64位系统。

的旧程序员使用了一些烦人的任务,比如将long

分配给int,这可能会导致数据丢失。


是否有可能让编译器(特别是GCC)在这种隐式类型转换上发出一些

警告?


或者你建议使用其他一些静态源代码分析工具?
Hello everyone,

I''m migrating a C++ program from 32-bit systems to 64-bit systems. The
old programmers used some annoying assignments like assigning "long"
to "int", which may lead to data loss.

Is it possible to let the compiler (specifically, GCC) spew some
warnings on this kind of implicit type casts?

Or you suggest use some other static source codes analysis tools?



任何好的编译器都应该在有数据丢失的风险时发出警告,你有没有提高警告级别?总是包含好的标志,当用gcc编译

是-Wall和-std = c ++ 98时,可能还有更多但是

这些是我能记得的现在。


-

Erik Wikstr ?? m

Any good compiler should warn when there is a risk of data loss, have
you turned up the warning levels? Good flags to always include when
compiling with gcc are -Wall and -std=c++98, there are probably more but
those are the ones I can remember right now.

--
Erik Wikstr??m


Erik Wikstr ?? m写道:
Erik Wikstr??m wrote:

2007-11-11 15:39, el ************ @ gmail.com 写道:

>大家好,
我正在将C ++程序从32位系统迁移到64位系统。老程序员使用了一些烦人的任务,比如将长分配给int,这可能会导致数据丢失。

是否可以让编译器(特别是,海湾合作委员会)对这种隐式类型演员发出一些警告?
>Hello everyone,

I''m migrating a C++ program from 32-bit systems to 64-bit systems. The
old programmers used some annoying assignments like assigning "long"
to "int", which may lead to data loss.

Is it possible to let the compiler (specifically, GCC) spew some
warnings on this kind of implicit type casts?



没有隐式类型转换。这是一个隐含的

转换。

There is no such thing as an implicit type cast. It''s an implicit
conversion.


>或者你建议使用其他一些静态源代码分析工具?
>Or you suggest use some other static source codes analysis tools?



任何好的编译器都应该在有数据丢失的风险时发出警告,你有没有提高警告级别?总是包含好的标志,当用gcc编译

是-Wall和-std = c ++ 98时,可能还有更多但是

这些是我能记得的现在。


Any good compiler should warn when there is a risk of data loss, have
you turned up the warning levels? Good flags to always include when
compiling with gcc are -Wall and -std=c++98, there are probably more but
those are the ones I can remember right now.



我建议也添加-pedantic和-Wextra。

I would suggest to also add -pedantic and -Wextra.


谢谢Erik和Rolf!


11月12日凌晨1点45分,Rolf Magnus< ramag ... @ t-online.dewrote:
Thanks Erik and Rolf!

On Nov 12, 1:45 am, Rolf Magnus <ramag...@t-online.dewrote:

没有隐式类型转换这样的东西。这是一个隐含的

转换。
There is no such thing as an implicit type cast. It''s an implicit
conversion.



好​​的,谢谢!

OK, thanks!


任何好的编译器都应该发出警告存在数据丢失的风险,你有没有提高警告级别?总是包含好的标志,当用gcc编译

是-Wall和-std = c ++ 98时,可能还有更多但是

这些是我能记得的现在。
Any good compiler should warn when there is a risk of data loss, have
you turned up the warning levels? Good flags to always include when
compiling with gcc are -Wall and -std=c++98, there are probably more but
those are the ones I can remember right now.



我建议也添加-pedantic和-Wextra。


I would suggest to also add -pedantic and -Wextra.



我试过-pedantic -Wall -Wextra -std = c ++ 98但是看不到有关此类错误的警告

。刚尝试了这样一个小程序:


#include< iostream>


使用命名空间std;

int main()

{

long l;

int i;


cout< < 输入长号:;

cin> l;

i = l;

cout<< int number是: << i<< endl;


返回0;

}

I''ve tried "-pedantic -Wall -Wextra -std=c++98" but see no warning
about such kind of error. Just tried a little program like this:

#include <iostream>

using namespace std;
int main ()
{
long l;
int i;

cout << "input a long number: ";
cin >l;
i = l;
cout << "the int number is: " << i << endl;

return 0;
}


这篇关于HOWTO:获取可能导致数据丢失的隐式类型转换的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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