C++NOW:有符号和无符号整数表达式(Freebsd、GCC、Gmake)之间的比较
C++ NOW: comparison between signed and unsigned integer expressions (Freebsd, GCC, Gmake )
我需要编译器生成的错误的帮助。
我希望你能帮助我。
这是错误消息:
FILE.cpp: In function 'int Gamble(std::vector<float, std::allocator<float> >&)':
FILE.cpp::6 :warning: comparison between signed and unsigned integer expressions
FILE.cpp:10: warning: comparison between signed and unsigned integer expressions
这是代码:
typedef std::vector <std::string> TTokenVector;
int Gamble(std::vector<float>& vec_probs)
{
float range = 0.f;
for (int i = 0; i < vec_probs.size(); i++) //Line 6
}
float fProb = fnumber(0.f, range);
float sum = 0.f;
for (int idx = 0; idx < vec_probs.size(); idx++) //LINE 10
{
sum += vec_probs[idx];
if (sum >= fProb)
return idx;
}
return -1;
}
默认编译程序是freebsd(GCC)
这是的罪魁祸首
for (int i = 0; i < vec_probs.size(); i++)
尝试
for (size_t i = 0; i < vec_probs.size(); i++)
int
类型是有符号的,size_t
类型(从.size()
返回)是无符号的。
相同的警告将出现在您的下一个for
循环中
(int idx = 0; idx < vec_probs.size(); idx++)
相关文章:
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 奇怪的结构&GCC&clang(void*返回类型)
- GCC本机矩阵运算库
- PowerPC ppc64le上的Gcc Woverloaded虚拟错误
- gcc和c++17的过载解析失败
- 数据成员SFINAE的C++17测试:gcc vs clang
- GCC对可能有效的代码抛出init list生存期警告
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 为什么与常规GCC不同,即使有"学究性错误",MinGW-GCC也能容忍丢失的返回类型
- 使用gcc从静态链接的文件中查找可选符号
- 普通环路未使用gcc 4.8.5自动矢量化
- 有了gcc,是否可以链接库,但前提是它存在
- 在clang++预处理器中确定gcc工具链版本
- 为什么 gcc 编译这个而 msvc 没有
- 为什么lambda在clang上崩溃而不是在gcc上崩溃
- 我可以检测和更改 gcc/g++ 中结构的当前数据对齐设置吗?
- gcc和clang在表达式是否为常量求值的问题上存在分歧
- C++NOW:有符号和无符号整数表达式(Freebsd、GCC、Gmake)之间的比较
- 使用GCC/GMake预编译头文件导致' pragma '警告(Premake)