GNU Style
Like the Allman and Whitesmiths styles, GNU style puts braces on a line by themselves, indented by 2 spaces, except when opening a function definition, where they are not indented. In either case, the contained code is indented by 2 spaces from the braces.
Popularised by Richard Stallman, the layout may be influenced by his background of writing Lisp code. In Lisp the equivalent to a block (a progn) is a first class data entity and giving it its own indent level helps to emphasize that, whereas in C a block is just syntax. Although not directly related to indentation, GNU coding style also includes a space before the bracketed list of arguments to a function.
static char * concat (char *s1, char *s2) { while (x == y) { something ; somethingelse ; } finalthing ; }This style combines the advantages of Allman and Whitesmiths, thereby removing the possible Whitesmiths disadvantage of braces not standing out from the block. One disadvantage is that the ending brace no longer lines up with the statement it conceptually belongs to.
The GNU Coding Standards recommend this style and nearly all maintainers of GNU project software use it.
The GNU Emacs text editor and the GNU systems' indent command will reformat code according to this style by default. Those who do not use GNU Emacs, or similarly extensible/customisable editors, may find that the automatic indenting settings of their editor are unhelpful for this style. However, many editors defaulting to KNF style cope well with the GNU style when the tab width is set to 2 spaces; likewise, GNU Emacs adapts well to KNF style just by setting the tab width to 8 spaces. In both cases, automatic reformatting will destroy the original spacing, but automatic line indentation will work correctly.
Read more about this topic: Indent Style
Famous quotes containing the word style:
“I would observe to you that what is called style in writing or speaking is formed very early in life while the imagination is warm, and impressions are permanent.”
—Thomas Jefferson (17431826)