1. Main Function File Layout (Section 3.2 of the C Style Guidebook)
Include files should only be included in a C program using the file name only; full path names should not be used. Use the '-I' option of the C compiler to allow the compiler to find the include file. This is primarily to allow your project to be easily moved to a different directory. Possible exceptions to the rule are path names that are not likely to change if the project source code is moved to another directory (e.g. /usr/local/db/db_defns.h).
2. Program Modularity (Functions) (Section 3.4.1 of the C Style Guidebook)
Be sure to make your functions of proper length and purpose as outlined in the Guidebook.
3. Use of Global Variables (Section 3.4.2 of the C Style Guidebook)
Make global variables static wherever possible. Use of global variables is discouraged, and use of non-static global variables (i.e. variables that are global between separate C source files) is extremely discouraged.
When using global variables, be sure to follow the naming conventions given in the Guidebook. That is, global variable names should begin with a single upper case character followed by lower case characters, and logically capitalized thereafter.
4. Comments (Section 3.5.1 of the C Style Guidebook)
Comments must be present as specified in the Guidebook. Block comments are encouraged; in-line comments are discouraged as they tend to clutter the source code. Do not comment the obvious; anything non-obvious should be commented with a block comment, or, preferably, avoided altogether.
5. Naming Conventions (Section 3.5.2 of the C Style Guidebook)
Names must be mnemonic. Take time to name your variables properly. Capitalization rules must be followed as outlined in the Guidbook; familiarize yourself with these rules. The following rules are particularly important:
- Global variables must begin with a capital letter
- Macros, typedefs and enums must be all upper case
- Local variables must begin with a lower case letter
- Function names must be lower case
6. Indentation (Section 3.5.3 of the C Style Guidebook)
All C code must be indented one tab stop for each indentation level. The tab character (^I) must be used for indentation. (The only exception to this rule is the indentation of a case clause within a switch statement. The case clause must not be indented with a tab, but instead may be indented with 2 or 4 spaces.)
7. Summary
The emphasis on the above aspects of C language style does not imply that all other issues outlined in the C Style Guidebook not mentioned here can be ignored. In general, these guidelines are being specified to make your code easier to work with and to read. Finally, do not 'back fit' these requirements into your assignments after you are otherwise done with the assignment. Become familiar with these rules, and develop your code with these rules in mind. It will ultimately make your tasks easier if you do so.