简体   繁体   English

sccz80:"../lib/main.c" L:16 警告:#14:预期的 ',' sccz80:"../lib/main.c" L:16 错误:#28:分段错误

[英]sccz80:"../lib/main.c" L:16 Warning:#14:Expected ',' sccz80:"../lib/main.c" L:16 Error:#28:Segmentation fault

I'm getting the following error on compilation of the code below:我在编译下面的代码时遇到以下错误:

sccz80:"../lib/main.c" L:16 Warning:#14:Expected ','
sccz80:"../lib/main.c" L:16 Error:#28:Segmentation fault
/*
 * A test game of Pong using the Z88dk
 */

#include <spectrum.h>
#include <graphics.h>
#include <sprites/sp1.h>
#include <stdio.h>

struct Bat {
    int x;
    int y;
    int w;
    int h;
};

void clear_screen(Bat* bat)
{
    undrawb(bat.x, bat.y, bat.w, bat.h);
}

int main()
{
    struct Bat bat;
    bat.x = 0;
    bat.y = 0;
    bat.w = 8;
    bat.h = 24;

    while(1)
    {
        zx_border(INK_GREEN);
        clear_screen(&bat);
        drawb(bat.x, bat.y, bat.w, bat.h);
    }
    return 0;
}

Any suggestions on what might be the issue?关于可能是什么问题的任何建议? I'm using the z88dk to create a test ZX Spectrum program.我正在使用 z88dk 创建一个测试 ZX Spectrum 程序。 Unfortunately, I don't have a high enough score to add a 'z88dk' tag.不幸的是,我没有足够高的分数来添加“z88dk”标签。 Apologies for that.对此表示歉意。

You have 2 errors in your program:您的程序中有 2 个错误:

void clear_screen(Bat* bat)
{
    undrawb(bat.x, bat.y, bat.w, bat.h);
}

There is no type Bat defined in your code.您的代码中没有定义类型Bat Only struct Bat .struct Bat Then bat is of type "pointer to struct".然后bat是“指向结构的指针”类型。 This means you cannot access the struct members using .这意味着您不能使用. operator but you need to dereference via -> .运算符,但您需要通过->取消引用。

It is really strange that your compiler provides an error message that does not contain any of these errors but instead mentions a line (assuming L:16 indicates line 16) and some reason that do not match the code.很奇怪,您的编译器提供的错误消息不包含任何这些错误,而是提到了一行(假设L:16表示第 16 行)和一些与代码不匹配的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM