Each function should be preceded by a block comment prologue that gives the name and a short description of what the function does. If the function returns a value, the type of the value returned should be alone on a line in column 1 (do not default to int). If the function does not return a value then it should not be given a return type. If the value returned requires a long explanation, it should be given in the prologue; otherwise it can be on the same line as the return type, tabbed over. The function name and formal parameters should be alone on a line beginning in column 1. Each parameter should be declared (do not default to int), with a comment on a single line. The opening brace of the function body should also be alone on a line beginning in column 1. The function name, argument declaration list, and opening brace should be separated by a blank line.
All local declarations and code within the function body should be tabbed over at least one tab.
If the function uses any external variables, these should have their own declarations in the function body using the extern keyword. If the external variable is an array the array bounds must be repeated in the extern declaration. There should also be extern declarations for all functions called by a given function. This is particularly beneficial to someone picking up code written by another. If a function returns a value of type other than int, it is required by the compiler that such functions be declared before they are used. Having the extern delcaration in the calling function’s declarations section avoids all such problems.
In general each variable declaration should be on a separate line with a comment describing the role played by the variable in the function. If the variable is external or a parameter of type pointer which is changed by the function, that should be noted in the comment. All such comments for parameters and local variables should be tabbed so that they line up underneath each other. The declarations should be separated from the function’s statements by a blank line.
A local variable should not be redeclared in nested blocks. Even though this is valid C, the potential confusion is enough that lint will complain about it when given the -h option.
* Determine if the sky is blue.
int /* TRUE or FALSE */
extern int hour;
if (hour < MORNING || hour > EVENING)
return(FALSE); /* black */
return(TRUE); /* blue */
* Find the last element in the linked list
* pointed to by nodep and return a pointer to it.
NODE * /* pointer to tail of list */
NODE *nodep; /* pointer to head of list */
register NODE *np; /* current pointer advances to NULL */
register NODE *lp; /* last pointer follows np */
np = lp = nodep;
while ((np = np->next) != NULL)
lp = np;