本文介绍了HOWTO:获取可能导致数据丢失的隐式类型转换的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我正在将C ++程序从32位系统迁移到64位系统。 的旧程序员使用了一些烦人的任务,比如将long 分配给int,这可能会导致数据丢失。 是否有可能让编译器(特别是GCC)在这种隐式类型转换上发出一些 警告? 或者你建议使用其他一些静态源代码分析工具? 提前致谢!Hello everyone,I''m migrating a C++ program from 32-bit systems to 64-bit systems. Theold 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 somewarnings on this kind of implicit type casts?Or you suggest use some other static source codes analysis tools?Thanks in advance!推荐答案 任何好的编译器都应该在有数据丢失的风险时发出警告,你有没有提高警告级别?总是包含好的标志,当用gcc编译 是-Wall和-std = c ++ 98时,可能还有更多但是 这些是我能记得的现在。 - Erik Wikstr ?? mAny good compiler should warn when there is a risk of data loss, haveyou turned up the warning levels? Good flags to always include whencompiling with gcc are -Wall and -std=c++98, there are probably more butthose are the ones I can remember right now.--Erik Wikstr??m 没有隐式类型转换。这是一个隐含的 转换。There is no such thing as an implicit type cast. It''s an implicitconversion. 任何好的编译器都应该在有数据丢失的风险时发出警告,你有没有提高警告级别?总是包含好的标志,当用gcc编译 是-Wall和-std = c ++ 98时,可能还有更多但是 这些是我能记得的现在。Any good compiler should warn when there is a risk of data loss, haveyou turned up the warning levels? Good flags to always include whencompiling with gcc are -Wall and -std=c++98, there are probably more butthose are the ones I can remember right now. 我建议也添加-pedantic和-Wextra。I would suggest to also add -pedantic and -Wextra. 好​​的,谢谢!OK, thanks! 我建议也添加-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 warningabout 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:获取可能导致数据丢失的隐式类型转换的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-03 04:21