错误:“正确”未在此范围内声明 pad.pvx*= -1; }

发布于 2024-09-27 06:41:00 字数 324 浏览 2 评论 0原文

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;
}

实际错误是什么? M无法打通。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

怎会甘心 2024-10-04 06:41:00

标准 C 语言中没有 TRUE 关键字。最有可能的是,这是您缺少的宏声明。从哪里获取它取决于您使用的编译器和库。如果找不到它的定义,将此代码放在 TRUE 的使用之前(在文件的开头,但在所有包含之后)将解决问题:

#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif

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
枕头说它不想醒 2024-10-04 06:41:00

由于您使用的是 bool 数据类型,看起来您正在 C99 中使用 stdbool.h 。如果是这种情况,那么您应该将 TRUE 更改为 true,后者扩展为 1

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.

薄荷→糖丶微凉 2024-10-04 06:41:00

我猜如果编译器说你的错误是 TRUE 没有在此范围内声明,那么这就是实际的错误。也许你应该定义 TRUE。另外,正如我在评论中指出的那样(在我查看标题之前),您最好甚至不要在此代码段中使用 TRUE 。与 C 中的 TRUE 进行比较可能会导致难以调试的微妙错误。 if (!alongX) 的意思就是你想说的,我发现它比 if (alongX == FALSE) 更清楚。

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).

时光礼记 2024-10-04 06:41:00

你应该在c中使用像int这样的东西而不是bool,只要它的值不是0它就是true,我会将其更改为

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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文