Suggested C coding standards
- Should be adopted by all members of software team
- Some groups adopt a formal style document.
- The goals of coding style are
- Portability
- Consistency
- Neatness
- Easy maintenance
- Easy understanding
- Simplicity
- Each source file should include a header
- Company name/address
- Copyright notice
- Filename
- Programmer's name
- Description
- Date
- Revision history
- Naming identifiers
- Hungarian
- Starts with lower-case letter(s) indicating data type
- Prefixed with "p_" or "a_" for pointers or arrays
- Descriptive variable name after prefix starts with capital letter
- Capital letters separate different parts of the identifier
- First part of identifier indicates the file name for variables that are static or global to the file
- Use acronyms and abbreviations consistently. For large projects these should be in the style guide.
- Use all upper-case characters for constants, macros, defined data types, and structure types.
- Comments: Line up comments in nearby lines
- Function prototypes should be declared in the same order the functions appear in the file
- Use four spaces per indentation level. Don't use tabs since different editors default to different widths.
- Use a space before
if, for, while, and do.
- Use a space after function names (before the parenthesis) in function declarations but not in function calls.
- Makes it easier to find the function using the editor's search feature
- Use no space around operators like string member "." and array subscripts "[]"
- Use a space before, and no space after, unary operators.
- Use space before and after binary operators
- Commas and semicolons within parentheses should have a space after them.