Lines Matching +full:hall +full:- +full:switch +full:-

1 .. include:: ../disclaimer-zh_CN.rst
3 :Original: :ref:`Documentation/process/coding-style.rst <codingstyle>`
32 --------------
47switch 语句中消除多级缩进的首选的方式是让 ``switch`` 和从属于它的 ``case``
50 .. code-block:: c
52 switch (suffix) {
71 .. code-block:: c
86 ------------------------------
99 ------------------------------
105 .. code-block:: c
111 这适用于所有的非函数语句块 (if, switch, for, while, do)。比如:
113 .. code-block:: c
115 switch (action) {
128 .. code-block:: c
142 .. code-block:: c
145 body of do-loop
150 .. code-block:: c
168 .. code-block:: c
175 .. code-block:: c
184 .. code-block:: c
204 if, switch, case, for, do, while
209 .. code-block:: c
215 .. code-block:: c
222 .. code-block:: c
230 = + - < > * / % | & ^ <= >= == != ? :
234 & * + - ~ ! sizeof typeof alignof __attribute__ defined
238 ++ --
242 ++ --
244 ``.`` 和 ``->`` 结构体成员操作符前后不加空格。
257 ------------------------------
259 C 是一个简朴的语言,你的命名也应该这样。和 Modula-2 和 Pascal 程序员不同,
282 -----------
288 .. code-block:: c
296 .. code-block:: c
356 ------------------------------
378 .. code-block:: c
391 ------------------------------
406 - 无条件语句容易理解和跟踪
407 - 嵌套程度减小
408 - 可以避免由于修改时忘记更新个别的退出点而导致错误
409 - 让编译器省去删除冗余代码的工作 ;)
411 .. code-block:: c
420 return -ENOMEM;
437 .. code-block:: c
440 kfree(foo->bar);
447 .. code-block:: c
450 kfree(foo->bar);
459 ------------------------------
470 当注释内核 API 函数时,请使用 kernel-doc 格式。请看
471 Documentation/doc-guide/ 和 scripts/kernel-doc 以获得详细信息。
475 .. code-block:: c
478 * This is the preferred style for multi-line
483 * with beginning and ending almost-blank lines.
488 .. code-block:: c
494 * but there is no initial almost-blank line.
503 ------------------------------
513 .. code-block:: none
515 (defun c-lineup-arglist-tabs-only (ignored)
517 (let* ((anchor (c-langelem-pos c-syntactic-element))
518 (column (c-langelem-2nd-pos c-syntactic-element))
519 (offset (- (1+ column) anchor))
520 (steps (floor offset c-basic-offset)))
522 c-basic-offset)))
524 (dir-locals-set-class-variables
525 'linux-kernel
526 '((c-mode . (
527 (c-basic-offset . 8)
528 (c-label-minimum-indentation . 0)
529 (c-offsets-alist . (
530 (arglist-close . c-lineup-arglist-tabs-only)
531 (arglist-cont-nonempty .
532 (c-lineup-gcc-asm-reg c-lineup-arglist-tabs-only))
533 (arglist-intro . +)
534 (brace-list-intro . +)
535 (c . c-lineup-C-comments)
536 (case-label . 0)
537 (comment-intro . c-lineup-comment)
538 (cpp-define-intro . +)
539 (cpp-macro . -1000)
540 (cpp-macro-cont . +)
541 (defun-block-intro . +)
542 (else-clause . 0)
543 (func-decl-cont . +)
545 (inher-cont . c-lineup-multi-inher)
546 (knr-argdecl-intro . 0)
547 (label . -1000)
549 (statement-block-intro . +)
550 (statement-case-intro . +)
551 (statement-cont . +)
554 (indent-tabs-mode . t)
555 (show-trailing-whitespace . t)
558 (dir-locals-set-directory-class
559 (expand-file-name "~/src/linux-trees")
560 'linux-kernel)
562 这会让 emacs 在 ``~/src/linux-trees`` 下的 C 源文件获得更好的内核代码风格。
570 指定选项 ``-kr -i8`` (代表 ``K&R,8 字符缩进``),或使用 ``scripts/Lindent``
578 ------------------------------
590 logging of avc messages output). Does not do system-call
601 要查看配置文件的完整文档,请看 Documentation/kbuild/kconfig-language.rst。
605 ------------------------------
629 ------------------------------
633 .. code-block:: c
643 含有多个语句的宏应该被包含在一个 do-while 代码块里:
645 .. code-block:: c
657 .. code-block:: c
662 return -EBUGGERED; \
670 .. code-block:: c
683 .. code-block:: c
690 .. code-block:: c
699 ret 是本地变量的通用名字 - __foo_ret 更不容易与一个已存在的变量冲突。
706 ------------------------------
727 许多子系统拥有 Kconfig 调试选项来开启 -DDEBUG 在对应的 Makefile 里面;在其他
733 ------------------------------
741 .. code-block:: c
754 .. code-block:: c
760 .. code-block:: c
768 ------------------------------
789 ------------------------------
792 的一个值可以表示为一个错误代码整数 (-Exxx=失败,0=成功) 或者一个 ``成功``
803 -EBUSY。类似的,因为 ``PCI device present`` 是一个判断,所以 pci_dev_present()
815 ------------------------------
820 .. code-block:: c
826 .. code-block:: c
828 #define sizeof_field(t, f) (sizeof(((t*)0)->f))
836 --------------------------------------------------
841 .. code-block:: c
843 -*- mode: c -*-
847 .. code-block:: c
851 compile-command: "gcc -DMAGIC_DEBUG_FLAG foo.c"
857 .. code-block:: c
867 ------------------------------
886 .. code-block:: c
894 ------------------------------
898 使用,再给 #else 提供一个空桩 (no-op stub) 版本,然后在 .c 文件内无条件地调用
913 .. code-block:: c
927 .. code-block:: c
935 -------------------
939 Prentice Hall, Inc., 1988.
940 ISBN 0-13-110362-8 (软皮), 0-13-110370-9 (硬皮).
944 Addison-Wesley, Inc., 1999.
945 ISBN 0-201-61586-X.
947 GNU 手册 - 遵循 K&R 标准和此文本 - cpp, gcc, gcc internals and indent,
950 WG14 是 C 语言的国际标准化工作组,URL: http://www.open-std.org/JTC1/SC22/WG14/
952 Kernel process/coding-style.rst,作者 greg@kroah.com 发表于 OLS 2002: