JasonWB007
Programmer
Hi everyone,
I hope this isn't too elementary for everyone, but what is the absolute strictest "proper" way to declare a C function and to access it in a separate file? Assume I have been sent to a military Catholic school for C programmers (Actually, we're looking at DO-178, something much stricter The options I have considered (so far) are:
1. Declare the function prototype in the beginning of the source file where it is defined. Declare the function as
"extern ..." in the beginning of every other C file where it is used.
2. Declare the function prototype in the header file of the same name as the C file where it is defined. Include that header file in every C file that accesses the function.
Any other suggestions? Option #1 has the disadvantage that there is no guarantee that the "extern" declaration in the other C files is correct. Option #2 has the disadvantage that sometimes I do not wish to have all of the information contained within the function's header file made available to every other C file that needs access to just that one function.
This seems to be a question on data hiding or something like that. What do you all think?
Thanks much!
Jason
I hope this isn't too elementary for everyone, but what is the absolute strictest "proper" way to declare a C function and to access it in a separate file? Assume I have been sent to a military Catholic school for C programmers (Actually, we're looking at DO-178, something much stricter The options I have considered (so far) are:
1. Declare the function prototype in the beginning of the source file where it is defined. Declare the function as
"extern ..." in the beginning of every other C file where it is used.
2. Declare the function prototype in the header file of the same name as the C file where it is defined. Include that header file in every C file that accesses the function.
Any other suggestions? Option #1 has the disadvantage that there is no guarantee that the "extern" declaration in the other C files is correct. Option #2 has the disadvantage that sometimes I do not wish to have all of the information contained within the function's header file made available to every other C file that needs access to just that one function.
This seems to be a question on data hiding or something like that. What do you all think?
Thanks much!
Jason