After reading a post, I embarked on another long rambling about #included header files (a topic that keeps popping up)
Reference Post: http://www.keil.com/forum/docs/thread14314.asp (And also a whole bunch of those #include/header file questions)
On that post, Per was on the correct path as far as inclusion (header) files.
Also, Andy is right when he explains about the function prototype 'extern' being used for completeness. Be complete.
I disagree with the questions on "slow computer", "max optimization", or the regularity of altering a single uber-header file simply because compile time on the computer. The compiler time should not a factor in building embedded code: GET A FASTER PC if you have a problem with that. (And if you like to compile after every few added lines, the you are simply hacking code and not really thinking about what you are doing during your code-monkey time).
The question of "small" or "large" program means nothing to me because even the 'small' programs will either have a single main.c file (module) or be broken into various .C modules--even for a small program. A large program will have many modules: if it doesn't then you have a serious problem with your code-monkey work anyway. (I've seen horror source code: a single .C file that contained EVERYTHING and had 10-15 conditional compile options---major retards worked on that piece of ___ ).
All .C source file shall have an associated .H file:
SPI.C shall also have a SPI.H file that SPI.C includes UART3.C shall also have a UART3.H file that UART3.C includes RoadKill.C shall also have a RoadKill.H file that RoadKill.C includes main.c shall also have a main.H file that main.c includes
If RoadKill.C needs access to SPI.C functionality, RoadKill.C shall include the SPI.H file for accessors and/or mutators or its SPI specific #defines.
If main.c needs RoadKill.C functionality and SPI functionality, then main.c shall also include both of those associated .H files (RoadKill.H and SPI.H).
All common .H files such as CPU reg definitions are part a the standard inclusion section. In that standard inclusion section, things that globally affect the system should go into that file be included in all modules. I have a header file called Logic.H which does some fairly simple things like the definition of TRUE and FALSE. Another it dTypes.H which has the typedfes for the data types ( #typedef unsigned char u8; etc. ).
Any global data should have its own "global_data.H" file (I use "gData.H" as my 'global data' header file (which is as empty as I can get it). I use main.C to ALLOCATE the data space, while all other modules REFERENCE (via 'extern') to the data-stores ("variables" for you non-engineer types).
Some people use alternate conditional compile pre-processor parameters. (I do not use them for code inclusion or exclusion)
#ifdef INCLUDE_DEBUG_CODE printf( "Code-Monkey Testing ID# %d) End-of-Conversion failed", debug_number ); debug_number++; // bump testing value #endif
ALL 'debug' code should be removed prior to qualification (which I'm sure you all do before you release it).
--Cpt. Vince Foster 2nd Cannon Place Fort Marcy Park, VA
<< more rambling to follow >>