Header file inclusions

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 >>

Parents
  • << continued post >>

    --OR--

    The commonly used shoe-horned *new* code for an alternate version of a product's software:

    
    /***********  For new the "Murmur-Maker 3000" pacemaker model **********/
    
    /*
    **  Compiler's Conditional Compiler settings are located in a separate .H
    **  file:
    **  e.g.
    **  CConfig.H
    */
    #define NEW_PACE_MAKER_CODE  1   // Enable the new code
    /* END OF CConfig.H file */
    
    
    /*--------------------------------------------------------------------------.
    ;   New Code added with the new model of the pacemaker hardware             ;
    '--------------------------------------------------------------------------*/
    #ifdef NEW_PACE_MAKER_CODE  // for the "Murmur-Maker 3000" pacemaker model
    /*
    **  Header file for MM2000.H
    **
    */
        ... // standard Murmer Maker 2000 model include file stuff
    
    /*--------------------------------------------------------------------------.
    ;   If the new model is to be used, then include it                         ;
    '--------------------------------------------------------------------------*/
    #ifdef NEW_PACE_MAKER_CODE  // for the "Murmur-Maker 3000" pacemaker model
    
    #include "MM3000.H" // added new stuff for the new model
    
    #endif
    
    /* END OF MM2000.H file */
    
    /*
    **  Header file for the MM3000.H specific include stuff..
    */
    
    
    /*--------------------------------------------------------------------------. ; #defines for MM3000 variant ; ;---------------------------------------------------------------------------; ;Values for the pacemaker's built-in AED-"Automated External Defibrillator" ; '--------------------------------------------------------------------------*/ #define AED_FIRST_DELAY 45 // seconds #define AED_SECOND_DELAY 25 // seconds
    #define AED_LOW_LEVEL 120 // from 120 to 200 joules for 'low level' AED zap #define AED_HIGH_LEVEL 360 // from 360 to 400 joules on 'high level' AED zap #define AED_HIGHEST_LEVEL 400 // from 360 to 400 joules on 'highest' AED zap
    #define AED_SMALL_DURATION 10 // milliseconds (aka "mS" -- don't complain about #define AED_MEDIUM_DURATION 15 // milliseconds the 'ms' versus 'mS' #define AED_LONGEST_DURATION 30 // milliseconds (in context, mS is correct)
    #define EMERGENCY_911 "911" // Phone Number for local 911 #define CORONERS_OFFICE "1.800.GUY.DEAD" // Phone Number for local coroner's office #define HUMAN_RESOURCES "1.800.MGR.EVIL" // Phone Number for company's HR manager #define ATTORNEY "1.800.BAD.GUYS" // Phone Number for an attorney
    #define EMERGENCY_911_MSG1 "Heart-Attack victim at %f Longitude, %f, Latitude: send ambulance" #define EMERGENCY_911_MSG2 "Heart-Attack victim at %f Longitude, %f, Latitude is better" #define LAWSUIT_MSG "Need huge settlement for non-responsive government due to %s" #define THE_REASON1 "Obambi's New Socialized Medicial Plan" #define THE_REASON2 "Obambi's Change"
    #define MAX_NAME_SIZE 50 // any name longer than that, and they shouldn't live anyway.
    /*--------------------------------------------------------------------------. ; Data-Store allocation for MM3000 variant ; '--------------------------------------------------------------------------*/ float GPS_Long; // location of victim float GPS_Lat; // location of victim u8 AED_Used; // { TRUE | FALSE } u32 Murmer_Maker_ID;// Victim's ID u8 who[ MAX_NAME_SIZE ];// Victim's name
    /*--------------------------------------------------------------------------. ; External prototype declarations ; ;---------------------------------------------------------------------------; ; These prototypes would actually be located in other .H include files ; ; but I put them here for the example. ; '--------------------------------------------------------------------------*/ extern void Built_In_AED_Shock( u8, u16, u16 ); // "Automated External Defibrillator" extern void AED_Wait( u16 ); // also from the AED.C module extern void Get_GPS( float *, float * ); // from GPS.C extern u16 Get_Pacemaker_Serial_Number( void ); // from new_features_module.C
    /* END OF MM3000.H file */

    You can figure out how to implement the 'extern' version of the data allocation methods for REFERENCE purposes yourself.

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

    << more rambling to follow >>

Reply
  • << continued post >>

    --OR--

    The commonly used shoe-horned *new* code for an alternate version of a product's software:

    
    /***********  For new the "Murmur-Maker 3000" pacemaker model **********/
    
    /*
    **  Compiler's Conditional Compiler settings are located in a separate .H
    **  file:
    **  e.g.
    **  CConfig.H
    */
    #define NEW_PACE_MAKER_CODE  1   // Enable the new code
    /* END OF CConfig.H file */
    
    
    /*--------------------------------------------------------------------------.
    ;   New Code added with the new model of the pacemaker hardware             ;
    '--------------------------------------------------------------------------*/
    #ifdef NEW_PACE_MAKER_CODE  // for the "Murmur-Maker 3000" pacemaker model
    /*
    **  Header file for MM2000.H
    **
    */
        ... // standard Murmer Maker 2000 model include file stuff
    
    /*--------------------------------------------------------------------------.
    ;   If the new model is to be used, then include it                         ;
    '--------------------------------------------------------------------------*/
    #ifdef NEW_PACE_MAKER_CODE  // for the "Murmur-Maker 3000" pacemaker model
    
    #include "MM3000.H" // added new stuff for the new model
    
    #endif
    
    /* END OF MM2000.H file */
    
    /*
    **  Header file for the MM3000.H specific include stuff..
    */
    
    
    /*--------------------------------------------------------------------------. ; #defines for MM3000 variant ; ;---------------------------------------------------------------------------; ;Values for the pacemaker's built-in AED-"Automated External Defibrillator" ; '--------------------------------------------------------------------------*/ #define AED_FIRST_DELAY 45 // seconds #define AED_SECOND_DELAY 25 // seconds
    #define AED_LOW_LEVEL 120 // from 120 to 200 joules for 'low level' AED zap #define AED_HIGH_LEVEL 360 // from 360 to 400 joules on 'high level' AED zap #define AED_HIGHEST_LEVEL 400 // from 360 to 400 joules on 'highest' AED zap
    #define AED_SMALL_DURATION 10 // milliseconds (aka "mS" -- don't complain about #define AED_MEDIUM_DURATION 15 // milliseconds the 'ms' versus 'mS' #define AED_LONGEST_DURATION 30 // milliseconds (in context, mS is correct)
    #define EMERGENCY_911 "911" // Phone Number for local 911 #define CORONERS_OFFICE "1.800.GUY.DEAD" // Phone Number for local coroner's office #define HUMAN_RESOURCES "1.800.MGR.EVIL" // Phone Number for company's HR manager #define ATTORNEY "1.800.BAD.GUYS" // Phone Number for an attorney
    #define EMERGENCY_911_MSG1 "Heart-Attack victim at %f Longitude, %f, Latitude: send ambulance" #define EMERGENCY_911_MSG2 "Heart-Attack victim at %f Longitude, %f, Latitude is better" #define LAWSUIT_MSG "Need huge settlement for non-responsive government due to %s" #define THE_REASON1 "Obambi's New Socialized Medicial Plan" #define THE_REASON2 "Obambi's Change"
    #define MAX_NAME_SIZE 50 // any name longer than that, and they shouldn't live anyway.
    /*--------------------------------------------------------------------------. ; Data-Store allocation for MM3000 variant ; '--------------------------------------------------------------------------*/ float GPS_Long; // location of victim float GPS_Lat; // location of victim u8 AED_Used; // { TRUE | FALSE } u32 Murmer_Maker_ID;// Victim's ID u8 who[ MAX_NAME_SIZE ];// Victim's name
    /*--------------------------------------------------------------------------. ; External prototype declarations ; ;---------------------------------------------------------------------------; ; These prototypes would actually be located in other .H include files ; ; but I put them here for the example. ; '--------------------------------------------------------------------------*/ extern void Built_In_AED_Shock( u8, u16, u16 ); // "Automated External Defibrillator" extern void AED_Wait( u16 ); // also from the AED.C module extern void Get_GPS( float *, float * ); // from GPS.C extern u16 Get_Pacemaker_Serial_Number( void ); // from new_features_module.C
    /* END OF MM3000.H file */

    You can figure out how to implement the 'extern' version of the data allocation methods for REFERENCE purposes yourself.

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

    << more rambling to follow >>

Children
More questions in this forum