mirror of
https://github.com/google/styleguide.git
synced 2024-03-22 13:11:43 +08:00
Update C++ style guide:
- Allow unsigned types where defined overflow behavior is desired - Clarify that a function-closing } is permitted on the same line as an opening { for one-line functions Set svn:eol-style = native on google-c-style.el
This commit is contained in:
parent
219b1a61fd
commit
db0be8e44d
10
cppguide.xml
10
cppguide.xml
|
@ -2149,8 +2149,9 @@ Tashana Landray
|
||||||
You should not use the unsigned integer types such as
|
You should not use the unsigned integer types such as
|
||||||
<code>uint32_t</code>,
|
<code>uint32_t</code>,
|
||||||
unless the quantity you are representing is really a bit pattern
|
unless the quantity you are representing is really a bit pattern
|
||||||
rather than a number. In particular, do not use unsigned types to
|
rather than a number, or unless you need defined
|
||||||
say a number will never be negative. Instead, use
|
twos-complement overflow. In particular, do not use unsigned
|
||||||
|
types to say a number will never be negative. Instead, use
|
||||||
|
|
||||||
assertions for this.
|
assertions for this.
|
||||||
</p>
|
</p>
|
||||||
|
@ -3472,8 +3473,9 @@ Tashana Landray
|
||||||
<li> The open curly brace is always at the end of the same
|
<li> The open curly brace is always at the end of the same
|
||||||
line as the last parameter.
|
line as the last parameter.
|
||||||
</li>
|
</li>
|
||||||
<li> The close curly brace is always on the last line by
|
<li> The close curly brace is either on the last line by itself
|
||||||
itself.
|
or (if other style rules permit) on the same line as the
|
||||||
|
open curly brace.
|
||||||
</li>
|
</li>
|
||||||
<li> There should be a space between the close parenthesis and
|
<li> There should be a space between the close parenthesis and
|
||||||
the open curly brace.
|
the open curly brace.
|
||||||
|
|
|
@ -1,108 +1,108 @@
|
||||||
;;; google-c-style.el --- Google's C/C++ style for c-mode
|
;;; google-c-style.el --- Google's C/C++ style for c-mode
|
||||||
|
|
||||||
;; Keywords: c, tools
|
;; Keywords: c, tools
|
||||||
|
|
||||||
;; google-c-style.el is Copyright (C) 2008 Google Inc. All Rights Reserved.
|
;; google-c-style.el is Copyright (C) 2008 Google Inc. All Rights Reserved.
|
||||||
;;
|
;;
|
||||||
;; It is free software; you can redistribute it and/or modify it under the
|
;; It is free software; you can redistribute it and/or modify it under the
|
||||||
;; terms of either:
|
;; terms of either:
|
||||||
;;
|
;;
|
||||||
;; a) the GNU General Public License as published by the Free Software
|
;; a) the GNU General Public License as published by the Free Software
|
||||||
;; Foundation; either version 1, or (at your option) any later version, or
|
;; Foundation; either version 1, or (at your option) any later version, or
|
||||||
;;
|
;;
|
||||||
;; b) the "Artistic License".
|
;; b) the "Artistic License".
|
||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
|
|
||||||
;; Provides the google C/C++ coding style. You may wish to add
|
;; Provides the google C/C++ coding style. You may wish to add
|
||||||
;; `google-set-c-style' to your `c-mode-common-hook' after requiring this
|
;; `google-set-c-style' to your `c-mode-common-hook' after requiring this
|
||||||
;; file. For example:
|
;; file. For example:
|
||||||
;;
|
;;
|
||||||
;; (add-hook 'c-mode-common-hook 'google-set-c-style)
|
;; (add-hook 'c-mode-common-hook 'google-set-c-style)
|
||||||
;;
|
;;
|
||||||
;; If you want the RETURN key to go to the next line and space over
|
;; If you want the RETURN key to go to the next line and space over
|
||||||
;; to the right place, add this to your .emacs right after the load-file:
|
;; to the right place, add this to your .emacs right after the load-file:
|
||||||
;;
|
;;
|
||||||
;; (add-hook 'c-mode-common-hook 'google-make-newline-indent)
|
;; (add-hook 'c-mode-common-hook 'google-make-newline-indent)
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
(defconst google-c-style
|
(defconst google-c-style
|
||||||
`((c-recognize-knr-p . nil)
|
`((c-recognize-knr-p . nil)
|
||||||
(c-enable-xemacs-performance-kludge-p . t) ; speed up indentation in XEmacs
|
(c-enable-xemacs-performance-kludge-p . t) ; speed up indentation in XEmacs
|
||||||
(c-basic-offset . 2)
|
(c-basic-offset . 2)
|
||||||
(indent-tabs-mode . nil)
|
(indent-tabs-mode . nil)
|
||||||
(c-comment-only-line-offset . 0)
|
(c-comment-only-line-offset . 0)
|
||||||
(c-hanging-braces-alist . ((defun-open after)
|
(c-hanging-braces-alist . ((defun-open after)
|
||||||
(defun-close before after)
|
(defun-close before after)
|
||||||
(class-open after)
|
(class-open after)
|
||||||
(class-close before after)
|
(class-close before after)
|
||||||
(namespace-open after)
|
(namespace-open after)
|
||||||
(inline-open after)
|
(inline-open after)
|
||||||
(inline-close before after)
|
(inline-close before after)
|
||||||
(block-open after)
|
(block-open after)
|
||||||
(block-close . c-snug-do-while)
|
(block-close . c-snug-do-while)
|
||||||
(extern-lang-open after)
|
(extern-lang-open after)
|
||||||
(extern-lang-close after)
|
(extern-lang-close after)
|
||||||
(statement-case-open after)
|
(statement-case-open after)
|
||||||
(substatement-open after)))
|
(substatement-open after)))
|
||||||
(c-hanging-colons-alist . ((case-label)
|
(c-hanging-colons-alist . ((case-label)
|
||||||
(label after)
|
(label after)
|
||||||
(access-label after)
|
(access-label after)
|
||||||
(member-init-intro before)
|
(member-init-intro before)
|
||||||
(inher-intro)))
|
(inher-intro)))
|
||||||
(c-hanging-semi&comma-criteria
|
(c-hanging-semi&comma-criteria
|
||||||
. (c-semi&comma-no-newlines-for-oneline-inliners
|
. (c-semi&comma-no-newlines-for-oneline-inliners
|
||||||
c-semi&comma-inside-parenlist
|
c-semi&comma-inside-parenlist
|
||||||
c-semi&comma-no-newlines-before-nonblanks))
|
c-semi&comma-no-newlines-before-nonblanks))
|
||||||
(c-indent-comments-syntactically-p . nil)
|
(c-indent-comments-syntactically-p . nil)
|
||||||
(comment-column . 40)
|
(comment-column . 40)
|
||||||
(c-cleanup-list . (brace-else-brace
|
(c-cleanup-list . (brace-else-brace
|
||||||
brace-elseif-brace
|
brace-elseif-brace
|
||||||
brace-catch-brace
|
brace-catch-brace
|
||||||
empty-defun-braces
|
empty-defun-braces
|
||||||
defun-close-semi
|
defun-close-semi
|
||||||
list-close-comma
|
list-close-comma
|
||||||
scope-operator))
|
scope-operator))
|
||||||
(c-offsets-alist . ((arglist-intro . ++)
|
(c-offsets-alist . ((arglist-intro . ++)
|
||||||
(func-decl-cont . ++)
|
(func-decl-cont . ++)
|
||||||
(member-init-intro . ++)
|
(member-init-intro . ++)
|
||||||
(inher-intro . ++)
|
(inher-intro . ++)
|
||||||
(comment-intro . 0)
|
(comment-intro . 0)
|
||||||
(arglist-close . c-lineup-arglist)
|
(arglist-close . c-lineup-arglist)
|
||||||
(topmost-intro . 0)
|
(topmost-intro . 0)
|
||||||
(block-open . 0)
|
(block-open . 0)
|
||||||
(inline-open . 0)
|
(inline-open . 0)
|
||||||
(substatement-open . 0)
|
(substatement-open . 0)
|
||||||
(statement-cont
|
(statement-cont
|
||||||
.
|
.
|
||||||
(,(when (fboundp 'c-no-indent-after-java-annotations)
|
(,(when (fboundp 'c-no-indent-after-java-annotations)
|
||||||
'c-no-indent-after-java-annotations)
|
'c-no-indent-after-java-annotations)
|
||||||
,(when (fboundp 'c-lineup-assignments)
|
,(when (fboundp 'c-lineup-assignments)
|
||||||
'c-lineup-assignments)
|
'c-lineup-assignments)
|
||||||
++))
|
++))
|
||||||
(label . /)
|
(label . /)
|
||||||
(case-label . +)
|
(case-label . +)
|
||||||
(statement-case-open . +)
|
(statement-case-open . +)
|
||||||
(statement-case-intro . +) ; case w/o {
|
(statement-case-intro . +) ; case w/o {
|
||||||
(access-label . /)
|
(access-label . /)
|
||||||
(innamespace . 0))))
|
(innamespace . 0))))
|
||||||
"Google C/C++ Programming Style")
|
"Google C/C++ Programming Style")
|
||||||
|
|
||||||
(defun google-set-c-style ()
|
(defun google-set-c-style ()
|
||||||
"Set the current buffer's c-style to Google C/C++ Programming
|
"Set the current buffer's c-style to Google C/C++ Programming
|
||||||
Style. Meant to be added to `c-mode-common-hook'."
|
Style. Meant to be added to `c-mode-common-hook'."
|
||||||
(interactive)
|
(interactive)
|
||||||
(make-local-variable 'c-tab-always-indent)
|
(make-local-variable 'c-tab-always-indent)
|
||||||
(setq c-tab-always-indent t)
|
(setq c-tab-always-indent t)
|
||||||
(c-add-style "Google" google-c-style t))
|
(c-add-style "Google" google-c-style t))
|
||||||
|
|
||||||
(defun google-make-newline-indent ()
|
(defun google-make-newline-indent ()
|
||||||
"Sets up preferred newline behavior. Not set by default. Meant
|
"Sets up preferred newline behavior. Not set by default. Meant
|
||||||
to be added to `c-mode-common-hook'."
|
to be added to `c-mode-common-hook'."
|
||||||
(interactive)
|
(interactive)
|
||||||
(define-key c-mode-base-map "\C-m" 'newline-and-indent)
|
(define-key c-mode-base-map "\C-m" 'newline-and-indent)
|
||||||
(define-key c-mode-base-map [ret] 'newline-and-indent))
|
(define-key c-mode-base-map [ret] 'newline-and-indent))
|
||||||
|
|
||||||
(provide 'google-c-style)
|
(provide 'google-c-style)
|
||||||
;;; google-c-style.el ends here
|
;;; google-c-style.el ends here
|
||||||
|
|
Loading…
Reference in New Issue
Block a user