Forward declaration of typedef structures in GBDK C

I use GBDK C to create a game for the original Game Boy, and I ran into a little problem. Each number in my game should have a different one portals, but each portalshould refer to a room. Here is the edited version of the code:

typedef struct {
    Portal portals[10];
} Room;

typedef struct {
    Room *destinationRoom;
} Portal;

Any suggestions on how to achieve this? I tried adding forward declaration struct Portal;to the beginning of the file, but that did not help.


Using the following code:

typedef struct Room Room;
typedef struct Portal Portal;

struct Room {
    Portal portals[10];
};

struct Portal {
    Room *destinationRoom;
};

Gives me this error:

parse error: token -> 'Room' ; column 11
*** Error in `/opt/gbdk/bin/sdcc': munmap_chunk(): invalid pointer: 0xbfe3b651 ***
+4
source share
1 answer

Reorder the definitions and write the declaration forward for the types Roomand Portal:

typedef struct Room Room;
typedef struct Portal Portal;

struct Portal {
    Room *destinationRoom;
};

struct Room {
    Portal portals[10];
};

, typedef Portal struct Portal , .

, ++, typedef , , struct Room;

- struct typedef, :

typedef struct Room_s Room;
typedef struct Portal_s Portal;

struct Portal_s {
    Room *destinationRoom;
};

struct Room_s {
    Portal portals[10];
};
+5

Source: https://habr.com/ru/post/1611130/


All Articles