Search code examples
clinuxzxspectrum

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. Unfortunately, I don't have a high enough score to add a 'z88dk' tag. Apologies for that.


Solution

  • You have 2 errors in your program:

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

    There is no type Bat defined in your code. Only struct Bat. Then bat is of type "pointer to struct". 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.