Ten Commandments for C Programmers (Summarized)
- Run lint frequently, fix warnings
- Don't follow the NULL pointer
- Cast all functions to their expected type
- If the headers don't declare the return types of a function, declare them yourself
- Check array bounds on all arrays, especially strings
- If a function can return error codes, check for them
- Don't reimplement library functions
- Use the One True Brace Style (i.e. K+R)
- Identifiers should be unique in the first six characters
- All the world is not a VAX (or a Sun, or a 386, or 32 bits, or...)
Specifically amusing quotes
- (1) ...does not mean mindless zeal to eradicate every byte of lint output-if for no other reason, because thou just canst not shut it up about some things...
- (3) Contrary to the heresies espoused by some of the dwellers on the Western Shore, `int' and `long' are not the same type.
- (3) Contrary to the beliefs common among the more backward inhabitants of the Polluted Eastern Marshes, `NULL' does not have a pointer type...
- (4) The prophet hath also commented that it is unwise, and leads one into the pits of damnation and subtle bugs, to attempt to declare such functions thyself when thy header files do the job right.
- (7) While it is true that some features of the C libraries were ill-advised, by and large it is better and cheaper to use the works of others than to persist in re-inventing the square wheel.
original, with annotation.
source: Henry Spencer
keywords: keywords
date: 03/18/2005