USDA ARS

Declarations

No more than one name should appear in a declaration. The ease of modification this affords is well worth the extra text consumed.

Local objects should be declared close to their point of first use. In practice, this implies that block-level declarations should be used freely, and that individual blocks should be kept short. Local declarations should never override declaration made at a higher level.

Local function declarations should be avoided, by one of the following techniques:

Declarations are indented at the same level as the block in which they occur. A storage class specifier, if present, is separated from the following type specifier by a single blank. In pointer declarations, identifiers with leading "*"s may be back-indented the appropriate number of spaces so that the first character of the identifier name aligns with other identifiers. An initializer, if present, is separated from the identifier by a single space.

Example:

{
        static bool_t   already = FALSE;  /* ? already called      */

        pixel_t        *buf;              /* -> image line buffer  */
        int             fd = ERROR;       /* image file descriptor */
        int             line;             /* image line #          */
        int             nlines;           /* # image lines         */

        ... C code ...

        for (line = 0; line < nlines; ++line) {
                 char  *bufp = buf;

                 ... C code ...
        }
}

Long integer constants in initializers should always include the trailing "L". Global and static variables that are not explicitly initialized will default to 0. If 0 is not a sensible value for such a variable, then it should be explicitly initialized.

If the declaration of an aggregate contains an initializer, then the initializer must be fully specified; don't omit trailing 0's. The only exception to this is a top-level global variable definition in a file by itself, which is being initialized only to force storage allocation.

Variable and function declarations are grouped according to the following criteria, and appear in the following order. Each group of declarations is followed by at least one blank line.

Within a block, definitions are grouped and ordered as follows:

"typedef" statements should always be top-level, and are formatted like ordinary declarations. Macros which represent possible values of a structure member should be "#define"d immediately following the structure's "typedef".


IPW documentation / Last revised 20 May 2009 / IPW web site