Suppose I define a struct in "struct.h" like so
struct box {
int value;
}
and I use that struct in another file say "math.c"
#include "struct.h"
struct box *sum(struct box *a1, struct box *a2) {
struct box *a3 = malloc(sizeof (struct box));
a3->value = a1->value + a2->value;
return a3;
}
would "math.h" need to include "struct.h" as well?
#include "struct.h"
struct box *sum(struct box *a1, struct box *a2);
And what if struct box were replaced with bool, do I need to include stdbool.h in both the header and c file? it seems like the compiler wants this.
When should you include files in the header rather than the .c? also wondering if theres something unusual with my example.
Thanks!