GNU Coding Standards - Code Formatting

Code Formatting

The GNU Coding Standards specify exactly how to format most C programming language constructs. Here is a characteristic example:

int main (int argc, char *argv) { struct gizmo foo; fetch_gizmo (&foo, argv); check: if (foo.type == MOOMIN) puts ("It's a moomin."); else if (foo.bar < GIZMO_SNUFKIN_THRESHOLD / 2 || (strcmp (foo.class_name, "snufkin") == 0) && foo.bar < GIZMO_SNUFKIN_THRESHOLD) puts ("It's a snufkin."); else { char *barney; /* Pointer to the first character after the last slash in the file name. */ int wilma; /* Approximate size of the universe. */ int fred; /* Max value of the `bar' field. */ do { frobnicate (&foo, GIZMO_SNUFKIN_THRESHOLD, &barney, &wilma, &fred); twiddle (&foo, barney, wilma + fred); } while (foo.bar >= GIZMO_SNUFKIN_THRESHOLD); store_size (wilma); goto check; } return 0; }

The consistent treatment of blocks as statements (for the purpose of indentation) is a very distinctive feature of the GNU C code formatting style; as is the mandatory space before parentheses. All code formatted in the GNU style has the property that each closing brace, bracket or parenthesis appears to the right of its corresponding opening delimiter, or in the same column.

As a general principle, GNU Emacs can be considered a reliable authority on the GNU code formatting style. As such, it is desirable that any piece of code that looks ugly when indented by Emacs is changed into a more Emacs-friendly form—for example, by inserting additional parentheses.

Read more about this topic:  GNU Coding Standards

Famous quotes containing the word code:

    Many people will say to working mothers, in effect, “I don’t think you can have it all.” The phrase for “have it all” is code for “have your cake and eat it too.” What these people really mean is that achievement in the workplace has always come at a price—usually a significant personal price; conversely, women who stayed home with their children were seen as having sacrificed a great deal of their own ambition for their families.
    Anne C. Weisberg (20th century)