If a function explicitly allocates storage, then it should either
"free"
the
storage before it returns, or pass a pointer to the storage back to the caller,
in which case the disposition of the storage becomes the caller's
responsibility.
Functions should always explicitly allocate any storage they require for their own use -- the practice of passing "work vectors" as arguments is strongly discouraged.
If a function is known to set the global variable "errno"
,
then "errno"
should
be cleared before, and examined after, every call to the function, unless
the function provides some other way to detect whether an error has
occurred (e.g., by a unique return value).
Source text lines should not contain more than 78 characters after tabs have been expanded into spaces.
In situations where the "++"
and "--"
operators
would have the same effect in either
prefix or postfix form, use the prefix form.
Example:
/* wrong */ /* right */ for (i = 0; i < n; i++) { for (i = 0; i < n; ++i) {
The expression following return
or sizeof
should
be enclosed in parentheses.
Finally, focus on getting a program or function to work before attempting to enhance its performance. The performance of a piece of code (usually taken to mean how fast it executes, but also often meaning how sparingly it uses machine resources) is of secondary concern to its maintainability, portability, and style:
It' s easier to get a working system efficient than it is to get an efficient system working. [Minow 1984]