Node:Style, Next:, Previous:Recursion, Up:Top



Style

C has no rules about when to start new lines, where to place whitespace, and so on. Users are free to choose a style which best suits them, but unless a strict style is adopted, sloppy programs tend to result.

In older compilers, memory restrictions sometimes necessitated bizarre, cryptic styles in the interest of efficiency. However, contemporary compilers such as GCC have no such restrictions, and have optimizers that can produce faster code than most programmers could write themselves by hand, so there are no excuses not to write programs as clearly as possible.

No simple set of rules will ever provide a complete methodology for writing good programs. In the end, experience and good judgment are the factors which determine whether you will write good programs. Nevertheless, a few guidelines to good style can be stated.

Many of the guidelines in this chapter are the distilled wisdom of countless C programmers over the decades that C has existed, and some come directly from the GNU Coding Standards. That document contains more good advice than can be crammed into this short chapter, so if you plan to write programs for the Free Software Foundation, you are urged to consult Table of Contents.