Pau*_*cks 5 c gcc warnings cell
我有以下代码
//Point.h
#define WIDTH 8
#define HEIGHT 8
typedef struct Point
{
char x;
char y;
} Point;
//Board.c
#include <stdbool.h>
// Some other functions that we don't care about...
bool inBounds(Point * p)
{
return p->x >= 0
&& p->x <= WIDTH
&& p->y >= 0
&& p->y <= HEIGHT;
}
Run Code Online (Sandbox Code Playgroud)
当我编译它(ppu-gcc 4.1.1)时,我收到以下警告
warning: comparison is always true due to limited range of data type
Run Code Online (Sandbox Code Playgroud)
即使char的范围是-127到127并且WIDTH是8,这完全在char的范围内.我已经尝试过对一个char进行WIDTH的显式转换,但仍然遇到了错误.
Dan*_*lau 15
你确定char
签了吗?尝试明确地声明字段signed char
,看看你得到了什么.