Preprocessor Directives
& Separate Compilation
#includes
- Only #include the header files at the top of a .c file that are needed
by the code in that file.
- Since the header file you have created for your modular functions,
(Let's call it foo.h) needs to be seen before the function definitions
(found in foo.c) and also any calls to those functions (found in
proj?.c), the header file foo.h needs to be #included at the top of
both the foo.c and the proj?.c files.
- Don't #include .c files.
.c files are to be compiled separately from one another and then
linked together at compile time.
- Don't have #includes of any files
within header files
Since header files contain prototypes and never have any function
calls in them, it isn't necessary to have any #include directives
in a header file.
#defines
For purposes of information hiding, you should place the #defines of constants
only as "high" in the program as they need to be.
- If a constant is used in only one .c file, then its #define should be
placed at the top of that file.
- If a constant is used by 2 .c files, then you should place the #define
for that constant in the header file that gets #included in both of
those .c files.
Last modified -