1

我在编译以下代码时收到以下错误:

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

关于可能是什么问题的任何建议?我正在使用 z88dk 创建一个测试 ZX Spectrum 程序。不幸的是,我没有足够高的分数来添加“z88dk”标签。对此表示歉意。

4

1 回答 1

2

您的程序中有 2 个错误:

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

Bat您的代码中没有定义类型。只有struct Bat. 然后bat是“指向结构的指针”类型。这意味着您无法使用.运算符访问结构成员,但您需要通过->.

很奇怪,您的编译器提供的错误消息不包含任何这些错误,而是提到了一行(假设L:16表示第 16 行)以及与代码不匹配的某些原因。

于 2019-12-26T11:04:36.327 回答