有符号/无符号比较警告是什么意思? [英] what does the signed/unsigned comparison warning mean?
本文介绍了有符号/无符号比较警告是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
auto.cpp: In function ‘int autooo(unsigned int)’:
auto.cpp:33:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
我正在做makefile文件,并且我已经运行了makefile文件并创建了一个auto.o文件,但仍然出现此错误,下面是我的autooo.cpp文件,auto.h文件
im doing the makefile , and i already run the makefile and make an auto.o but still i get this error, below is my autooo.cpp , auto.h
我不理解未签名和已签名的内容:\请帮助
i dont undestand what is unsigned and signed :\ please help
auto.h
#ifndef function_H_
#define function_H_
int autooo(unsigned);
int interr(unsigned);
#endif /* function_H_ */
autooo.cpp
autooo.cpp
#include <iostream>
#include <cstdlib> //for random functions
#include "prime.h"
#include "auto.h"
using namespace std;
#ifndef auto_CPP_
#define auto_CPP_
int autooo(unsigned);
int autooo(unsigned a)
{
int b=50;
unsigned numberFound = 0;
do
{
++a;
if (isPrime(a))
{
++numberFound;
cout << a << "is prime number" <<endl;
}
} while (numberFound < b);
return 0;
}
#endif
推荐答案
编译器警告该代码在行中包含 unsigned int
与 signed int
的比较
The compiler warns that the code contains comparison of unsigned int
with a signed int
in the line
while (numberFound < b);
这与makefile或make无关.
This has nothing to do with makefiles or make.
您可以通过更改来解决
int b=50;
到
unsigned b = 50;
或通过更改
unsigned numberFound = 0;
到
int numberFound = 0;