The formatting rules for GCC are described in http://gcc.gnu.org/contribute.html and in http://gcc.gnu.org/codingconventions.html.

If you use Emacs, you can use M-x c-set-style and type 'gnu' for the style. And also, you can configure like this in your ~/.emacs file:

;; This line is not actually needed, it is on by default.
(setq-default indent-tabs-mode t)

(add-hook 'c-mode-hook 'linux-c-mode)
(defun linux-c-mode()
;; set gnu style.
 (c-set-style "gnu")
;; TAB offset set to 2
 (setq c-basic-offset 2)
 )

Alternatively, on Emacs 23.1 or later, you can use directory-specific variables. Create a file .dir-locals.el in some directory between root and GCC sources with following contents:

((c-mode . ((c-file-style . "GNU")
            (c-basic-offset . 2)
            (indent-tabs-mode t))))

If you use Vim, you can use the following settings:

$ cat ~/.vim/after/ftplugin/c.vim
GNU Coding Standards
setlocal cindent
setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1
setlocal shiftwidth=2
setlocal softtabstop=2
setlocal textwidth=79
setlocal fo-=ro fo+=cql

None: FormattingCodeForGCC (last edited 2010-05-27 12:08:38 by LaurynasBiveinis)