Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!uunet!brunix!gvr From: gvr@cs.brown.edu (George V. Reilly) Newsgroups: comp.lang.c Subject: Re: Braces Message-ID: <64002@brunix.UUCP> Date: 7 Feb 91 06:04:38 GMT References: <2293@inews.intel.com> <15090@smoke.brl.mil> <2324@inews.intel.com> <15102@smoke.brl.mil> Sender: news@brunix.UUCP Reply-To: gvr@cs.brown.edu (George V. Reilly) Organization: Brown University Department of Computer Science Lines: 66 In article <2324@inews.intel.com> bhoughto@pima.intel.com (Blair P. Houghton) writes: % ... I'd like to know where it came from, not the reasons % or rationalizations for its use: those I'll get from the % source. The jargon file, version 2.5.1, has this to say on the matter of indent styles: [C programmers] n. The rules one uses to lay out code in a readable fashion; a subject of . There are four major C indent styles, as described below; all have the aim of making it easier for the reader to visually track the scope of control constructs. The significant variable is the placement of { and } with respect to the statement(s) they enclose and the guard (if, while, or do) on the block, if any. "K&R style" --- Named after Kernighan & Ritchie, because the examples in are formatted this way. Also called "kernel style" because the UNIX kernel is written in it. The basic indent shown here is 8 spaces (or 1 tab) per level; 4 is occasionally seen but much less common. if (cond) { } "Allman style" --- Named for Eric Allman, a Berkeley hacker who wrote a lot of the BSD utilities in it (it is sometimes called "BSD style"). Resembles normal indent style in Pascal and Algol. Basic indent per level shown here is 8 spaces, but 4 is just as common (esp. in C++ code). if (cond) { } "Whitesmiths style" --- popularized by the examples that came with Whitesmiths C, an early commercial C compiler. Basic indent per level shown here is 8 spaces, but 4 is occasionally seen. if (cond) { } "GNU style" --- Used throughout GNU EMACS and the Free Software Foundation code, and just about nowhere else. Indents are always 4 spaces per level, with { and } "centered" between levels. if (cond) { } What style one uses is very much a matter of personal choice, but one should be consistent within any one software package. Statistically, surveys have shown the Allman and Whitesmiths styles to be the most common, with about equal `mind share'. K&R used to be nearly universal, but is now much less common (the opening brace tends to get lost against the right paren of the guard part in an if or while, which is a Bad Thing). ________________ George V. Reilly `Brace yerself, Bridget' gvr@cs.brown.edu +1(401)863-7684 uunet!brunix!gvr gvr@browncs.bitnet Box 1910, Brown U, Prov, RI 02912