[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

2. General

General standards:

ANSI compliance
Know the ANSI C89 and C99 standards. Comply to them where possible. Make sure that any violations are intentional. Add comments explaining assumptions in the machine or the compiler implementation that go beyond guarantees given in the standards. If it is possible to test for a required implementation property, do so and issue an #error if it is not present.

other standards
Standards other than ANSI C exist. Understand the standards to which a programs complies.

line length
Limit source code lines to 79 characters or less.

tab width
Tabs are 8 characters in width. This doesn't mean that indentations are 8 characters in width: a good programmer's editor is smart enough to decide when to use tabs and when to use spaces to make up whatever quantity of indentation is needed.

compiler extensions
Avoid C language extensions except where fallback to a portable substitute is possible. In that case, use the extension only if a compiler supporting it is detected.

It is okay to use nonessential compiler extensions that can simply be disabled on other compilers. In particular, GCC's __attribute__ ((format (...))) is handy.

The same applies to new features in C99.

warnings
Code should compile clean on GCC with options -Wall -W -Wpointer-arith -Wstrict-prototypes. Another option to consider using is -Wwrite-strings. Options -ansi -pedantic are good for finding standards violations, but compiling clean against them is not always realistic for real-world code, especially as sometimes system headers trigger warnings from these options. Additionally, -fno-builtin can find mistakes, but using it for release versions may not be desirable. Finally, -Werror is good for development but not release.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Ben Pfaff on September, 11 2001 using texi2html