I’m working on a fairly simple C program with a main file, vector.c, vector.h, but I’m running into these issues:
- where do I put the include for a .h file if the declarations it provides are needed in both c files?
- where do I put typedefs needed in all 3 files?
seems like gcc complains no matter what I do.
Can anyone answer these questions, or point me toward a resource I can read?
Put
includestatements in each C file that requires the header definitions, in your case, in main.c and vector.c. Using include guards is always a good idea, and required if the compiler is complaining about symbols being already defined or multiply defined.It depends:
typedefsare necessary for, or specific to your vector API, then put them in vector.h.typedefsaren’t part of your vector interface then they probably belong to a 3rd header file, for example something like common.h, which might also be included by every other file in your project.