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