c - Including .h files for functions -
i passing struct pointer function in .c file. need include header file in both .c files?
//test.h typedef struct { int number; } stats; //test.c #include "test.h" void function(){ func2(s); } //stats.c //do need : include "test.h" void func2(stats * ptr){ ptr->number = 10; }
yes, stats.c
needs structure definition in order know num
member in stats
structure.
if passing pointer along other function, wouldn't need structure definition; need forward declaration of structure type name; structure pointers required compatible way, , allows pointer treated opaque handle. since func2
accesses member, it's not opaque.
Comments
Post a Comment