这是我的OpenGL代码的一部分,我遇到了以下错误:
struct Ball {
float x;
float y;
float rot;
float dir;
bool rmv;
Ball* next;
};
Ball* curBall;
void addBall() {
if (balls==NULL) {
balls=new Ball;
balls->next=NULL;
curBall=balls;
} else {
curBall->next=new Ball;
curBall=curBall->next;
curBall->next=NULL;
}
curBall->x=((float)rand()/(float)(RAND_MAX+1))*(ww-1) +1;
curBall->y=((float)rand()/(float)(RAND_MAX+1))*(wh-1) +1;
curBall->dir=((float)rand()/(float)(RAND_MAX+1))*(2*PI-1) +1;
curBall->rot=((float)rand()/(float)(RAND_MAX+1))*(359) +1;
curBall->rmv=false;
}
error :
In function ‘void addBall()’:
file.cpp:120: warning: integer overflow in expression
file.cpp:121: warning: integer overflow in expression
file.cpp:122: warning: integer overflow in expression
file.cpp:123: warning: integer overflow in expression
(static_cast<float>(RAND_MAX) + 1.0f) == static_cast<float>(RAND_MAX)
,因为在浮点数中没有足够的位来表示每个整数,加法将被截断回去。 - Mark Bprintf(“%d \ n”,RAND_MAX);
来查看您正在针对的每个平台的结果。 - dash-tom-bang