The Psychology of Quality and More |
CHAPTER 7 : File Layout
7.5 Layout of Data filesWhen a number of functions, spread across several files, refer directly to a global data object, where should that object be defined? If it is not 'owned' by any single file, then the answer is to put it in a global data file. 7.5.1 Division and layout of data filesThe division and layout of data files should broadly follow the rules for header files. Thus a typical format might be:
File heading comment Identification/copyright string Include files Common context items: #define's, enum's Functional area 1: Heading comment #define's, enum's for context Data definition 1: Heading comment #define's, enum's for context typedef or struct to define data item Data definition 2: ... Functional area 2: ... 7.5.2 Header files and data filesDeclaring the context within the data file may cause problems where that context is also required within the code that references the data. One way of avoiding duplicate declarations is to put the external references to the data in a header file, created from a copy of the data file (thus simply ensuring that they match):
/* kbddata.h */ -------------------------------------------------------------------------- Having to keep two sets of data like this may cause maintenance problems, although the inclusion of the header file containing the extern in the data file will cause the compiler to flag any inconsistencies. An alternative is to use the preprocessor to make the header file dual purpose:
/* kbddata.h */
|
Site Menu |
Quality: | Quality Toolbook | Tools of the Trade | Improvement Encyclopedia | Quality Articles | Being Creative | Being Persuasive | |
And: | C Style (Book) | Stories | Articles | Bookstore | My Photos | About | Contact | |
Settings: | Computer layout | Mobile layout | Small font | Medium font | Large font | Translate | |
You can buy books here |
And the big |