error: ‘TRUE’ was not declared in this scope pad.pvx*= -1; }
void move_paddle(PADDLE pad, bool alongX)
{
if(alongX!=TRUE)
{
if((pad.py+pad.length/2)>=B || (pad.py-pad.length/2)<=BB)
pad.pvx*= -1;
}
else if((pad.px+pad.length/2)>=A || (pad.py-pad开发者_运维知识库.length/2)<=AA)
pad.pvx*= -1;
}
What is the actual error ? M unable to get through.
There is no TRUE
keyword in standard C language. Most probably, this is a macro declaration that you are missing. Where to get it depends on what compiler and libraries you are using. If you cannot find its definition, putting this code before the usage of TRUE (in the beginning of the file, but after all includes) will fix the problem:
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif
Since you are using bool
data type, looks like you are using stdbool.h
in C99. If that is the case then you should change TRUE
to true
which expands to 1
.
I'm guessing that if the compiler says your error is that TRUE is not declared in this scope, then that's the actual error. Maybe you should define TRUE. Also, as I pointed out in my comment (before I had looked at the title) you're probably better off not even using TRUE
in this snippet anyway. Comparing vs. TRUE
in C is likely to lead to subtle errors that are hard to debug. if (!alongX)
means what you wanted to say, and I find it clearer than if (alongX == FALSE)
.
You should use something like an int instead of a bool in c, and as long as it's value ain't 0 it's true, I would change this to
void move_paddle(PADDLE pad, int alongX)
{
if(!alongX)
{
if((pad.py+pad.length/2)>=B || (pad.py-pad.length/2)<=BB)
pad.pvx*= -1;
}
else if((pad.px+pad.length/2)>=A || (pad.py-pad.length/2)<=AA)
pad.pvx*= -1;
}
精彩评论