STYLE revision 1.7 1 1.7 gehenna $NetBSD: STYLE,v 1.7 2002/09/06 13:18:43 gehenna Exp $
2 1.1 cgd
3 1.1 cgd Style guide for NetBSD/alpha kernel files.
4 1.1 cgd
5 1.1 cgd This file is meant to supplement the NetBSD KNF style guide (which covers
6 1.1 cgd most of the rest of the system, and can be found in /usr/share/misc/style).
7 1.1 cgd
8 1.1 cgd
9 1.1 cgd SECTIONS
10 1.1 cgd
11 1.1 cgd * INCLUDE FILES
12 1.1 cgd * RCS IDS
13 1.1 cgd * COMPILATION FLAGS
14 1.1 cgd * MACRO DEFINITIONS
15 1.1 cgd * BLOCKS AND EXPRESSIONS
16 1.1 cgd
17 1.1 cgd
18 1.1 cgd INCLUDE FILES
19 1.1 cgd
20 1.4 thorpej (1) All option headers should be included first, and sorted, like:
21 1.4 thorpej
22 1.4 thorpej #include "opt_dec_3000_300.h"
23 1.4 thorpej #include "opt_dec_3000_500.h"
24 1.4 thorpej
25 1.4 thorpej (2) All C sources should include <sys/cdefs.h> as the first header to
26 1.4 thorpej be included after any option headers, with a line like:
27 1.1 cgd
28 1.1 cgd #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
29 1.1 cgd
30 1.1 cgd
31 1.1 cgd RCS IDS
32 1.1 cgd
33 1.7 gehenna (1) NetBSD RCS ID tags ($NetBSD: STYLE,v 1.7 2002/09/06 13:18:43 gehenna Exp $ tags) in C sources and headers should
34 1.1 cgd appear at the top of the file in a single-line comment of the form
35 1.1 cgd
36 1.7 gehenna /*<space>$NetBSD: STYLE,v 1.7 2002/09/06 13:18:43 gehenna Exp $<space>*/
37 1.1 cgd
38 1.1 cgd which differs from the normal NetBSD style, in that it uses spaces
39 1.5 wiz rather than tabs to separate the tag from the comment start and end
40 1.1 cgd delimiters.
41 1.1 cgd
42 1.2 cgd (2) All C and assembler sources should include an RCS ID tag which can
43 1.2 cgd be compiled into the binary, with a line like:
44 1.1 cgd
45 1.7 gehenna __KERNEL_RCSID(0, "$NetBSD: STYLE,v 1.7 2002/09/06 13:18:43 gehenna Exp $");
46 1.1 cgd
47 1.2 cgd after the inclusion of cdefs.h. Source files which include other source
48 1.2 cgd files should change the number '0' to a different number, so that it
49 1.6 wiz doesn't conflict with the RCS ID definitions in included sources.
50 1.2 cgd Generation of these RCS IDs is disabled if the kernel option
51 1.2 cgd NO_KERNEL_RCSIDS is defined. (In some cases, picking the number to use
52 1.2 cgd may not be so straightforward, but the rule above usually works.)
53 1.1 cgd
54 1.1 cgd
55 1.1 cgd COMPILATION FLAGS
56 1.1 cgd
57 1.1 cgd By default, NetBSD/alpha kernel files are compiled with the following gcc
58 1.1 cgd warning flags:
59 1.1 cgd
60 1.1 cgd -Werror
61 1.1 cgd -Wall
62 1.1 cgd -Wstrict-prototypes
63 1.1 cgd -Wmissing-prototypes
64 1.1 cgd -Wno-format
65 1.1 cgd
66 1.1 cgd NetBSD/alpha kernel code should compile cleanly with those flags. At some
67 1.1 cgd point in the future (when the nonstandard extensions have been removed
68 1.1 cgd from the kernel printf() function), -Wformat will be re-enabled, so sources
69 1.1 cgd should be able to compile with it enabled as well.
70 1.1 cgd
71 1.1 cgd
72 1.1 cgd MACRO DEFINITIONS
73 1.1 cgd
74 1.1 cgd (1) Macros which use C blocks (i.e. are of the form "{ ... expressions
75 1.1 cgd ... }") should always be defined like:
76 1.1 cgd
77 1.1 cgd #define MACRO(arg1, arg2, argN) \
78 1.1 cgd do { \
79 1.1 cgd ... \
80 1.1 cgd expressions \
81 1.1 cgd ... \
82 1.1 cgd } while (0)
83 1.1 cgd
84 1.1 cgd so that they behave like functions or macros which don't use blocks (e.g.
85 1.1 cgd for the purpose of "if (foo) MACRO(); else ...").
86 1.1 cgd
87 1.1 cgd
88 1.1 cgd BLOCKS AND EXPRESSIONS
89 1.1 cgd
90 1.1 cgd (1) Surround blocks with { and } more often than is absolutely necessary.
91 1.1 cgd For instance:
92 1.1 cgd
93 1.1 cgd if (foo)
94 1.1 cgd bar();
95 1.1 cgd
96 1.1 cgd is acceptable, but:
97 1.1 cgd
98 1.1 cgd if (foo) {
99 1.1 cgd bar();
100 1.1 cgd }
101 1.1 cgd
102 1.1 cgd is preferred. (In contrast, NetBSD KNF says that no braces are to be
103 1.1 cgd used for control statements with zero or one statements.)
104 1.1 cgd
105 1.1 cgd (2) Use extra parentheses when it makes expressions clearer. For instance,
106 1.1 cgd
107 1.1 cgd (foo == 10 && bar == 20)
108 1.1 cgd
109 1.1 cgd is acceptable, but:
110 1.1 cgd
111 1.1 cgd ((foo == 10) && (bar == 20))
112 1.1 cgd
113 1.1 cgd is preferred. (In contrast, NetBSD KNF says to avoid using parentheses
114 1.1 cgd except where necessary unless the expression is very confusing without
115 1.1 cgd them.)
116