Project in C. Not sure about way i did it my project
Hi I just done my project for school. I am just not sure about way i did it.
I have files:
headers.h - i keep here all headers of functions (decla开发者_如何学运维ration) and public variables.
save_sunctions.c - definition of some functions
move_sunctions.c - definition of some functions
loop_sunctions.c - definition of some functions
goone_sunctions.c - definition of some functions
main.c - in this file i use all of these functions.
Is it good? Or I should use "extern" or something else?
I think it is more conventional to have a one-to-one relationship between header files and source files. That way you can, in another project, include just a portion of the code, without including header declarations for lots of functions that do not have definitions in the project.
So, for each .c
file have a corresponding .h
file with the same name that declares each function in the .c
file.
You will need to add what is known as a guard to each header file to ensure it is only included once. Guards look like this:
#ifndef GO_FUNCTIONS_GUARD
#define GO_FUNCTIONS_GUARD
.../* declarations go here
#endif
As for extern
, there's no need for that in what you describe. Just stick to header files.
Generally you should try to keep all similar code together. In my opinion, each .c
file should have it's own .h
file to refer to. I think you probably over separated the files, but that is subject to interpretation.
精彩评论