I'm writing a c program using curses library, and want to create some structs reflecting my application UI.
Here's my app.c file
#include <stdlib.h>
#include <stdio.h>
#include "screen.h"
int main() {
struct screen scr = {
.win1 = {
.title = "win1"
},
.win2 = {
.title = "win2"
}
};
}
here's screen.h
#ifndef SCREEN_H
#define SCREEN_H
#include "window.h"
struct screen {
struct window win1;
struct window win2;
struct window *focused;
};
#endif
and here's window.h
#ifndef WINDOW_H
#define WINDOW_H
#include "screen.h"
struct window {
char *title;
void (*handle_key_event)(struct screen*);
};
#endif
My window struct handle method must receive a reference to screen, to be able to change the focused window in some specific cases. But when I compile this, I get the warning
window.h:8:34: warning: its scope is only this definition or declaration, which is probably not what you want
which is because it doesn't see the screen declaration. How to fix this?
struct screen;there instead of including screen.h. I'd guess the error is that it thinks you're declaring a struct screen inside struct window, but I'm not sure exactly how it'd parse it like that.