I roughly understand the rules with what #include does with the C preprocessor, but I don’t understand it completely. Right now, I have two header files, Move.h and Board.h that both typedef their respective type (Move and Board). In both header files, I need to reference the type defined in the other header file.
Right now I have #include “Move.h” in Board.h and #include “Board.h” in Move.h. When I compile though, gcc flips out and gives me a long (what looks like infinite recursive) error message flipping between Move.h and Board.h.
How do I include these files so that I’m not recursively including indefinitely?
You need to look into forward declarations, you have created an infinite loops of includes, forward declarations are the proper solution.
Here’s an example:
Move.h
Board.h
main.c
Note: whenever you create a “Board”, you will need to do something like this (there are a few ways, here’s an example):