I use the following code to create various structures, but I give people outside the C file a pointer to it. (Yes, I know that they could potentially run into it, so this doesn't exactly look like a personal keyword in Java, but it's good with me).
Anyway, I used the following code, and today I watched it, and I am very surprised that it really works, can someone explain why this is?
In my C file, I create my structure but don’t give it a tag in the typedef namespace:
struct LABall { int x; int y; int radius; Vector velocity; };
And in file H I put this:
typedef struct LABall* LABall;
I obviously use #include "LABall.h" in the c file, but I DO NOT use #include "LABall.c" in the header file, as this will hit the target of a separate header file. So, why can I create a pointer to the LABall * structure in the H file, if I haven't included it at all? Does this have anything to do with the struct namespace working on files, even if one file is in no way related to another?
Thanks.
c include struct typedef
Leif andersen
source share