# Function Body Layout

With the body of functions, this is the way we aim to do it. We are not religious about it, but consistency helps. We use an indentation form that is known as the BSD c style. If you think your way is smarter, you may be right but this is the way we do it ;-). The format is also pretty close to the one you find in The C Programming Language by Kernighan and Ritchie.

- Put opening { at the end of the same line as the `if`, `while`, etc which affects the block
- Align the closing brace with the START of that opening line
- Indent everything between { and } by an extra 4 spaces, like the following example:

              for (i=0; i<2; i++) { HTList *cur = conversions[i]; HTPresentation *pres; while ((pres =(HTPresentation *) HTList_nextObject(cur))) { if (pres->rep_out == WWW_PRESENT) {
                          if (pres->quality != 1.0) {
                              sprintf(line, "Accept: %s; q=%.3f%c%c",
                                      HTAtom_name(pres->rep),
                                      pres->quality, CR, LF);
                          } else {
                              sprintf(line, "Accept: %s%c%c",
                                      HTAtom_name(pres->rep), CR, LF);
                          }
                          HTChunkPuts(command, line);
                      }
                  }
              }

  You can get your emacs to do automatic indentation according to those rules by adding the following to your local `.emacs` file:

      ;; C style indentation
      ;; =====================
      (defun w3c-c-mode-common-hook ()
        ;; use BSD for all C, C++, and Objective-C code
        (c-set-style "BSD")
        ;; other customizations can go here
        (setq c-tab-always-indent nil)
        )
      (add-hook 'c-mode-common-hook 'w3c-c-mode-common-hook)

- Do not make lines wider than 80 characters. Otherwise it gets very difficult to read on a 80 character screen.
- Never indent preprocessor instructions (#ifdef, etc), nor increase the indentation level on account of preprocessor instructions (many preprocessors do not understand indented directives)
- Block comments should start with /* in column 1, end end with */ in column 1. In between, having ** in column 1 is conventional but not necessary for very large comments. A good example is:

      /*
      ** This is a comment that spans several lines. If you want to do this
      ** then please use the comment markers as indicated. Do not use
      ** C++ style comments - they are not portable
      */

Remember to use comments in the source code - it makes life easier for everybody