xref: /netbsd-src/sys/arch/alpha/STYLE (revision 77a6b82b27fa24d81a68a73afb1c4158bfb664ba)
1*77a6b82bSgehenna$NetBSD: STYLE,v 1.7 2002/09/06 13:18:43 gehenna Exp $
2effe625aScgd
3effe625aScgdStyle guide for NetBSD/alpha kernel files.
4effe625aScgd
5effe625aScgdThis file is meant to supplement the NetBSD KNF style guide (which covers
6effe625aScgdmost of the rest of the system, and can be found in /usr/share/misc/style).
7effe625aScgd
8effe625aScgd
9effe625aScgdSECTIONS
10effe625aScgd
11effe625aScgd	* INCLUDE FILES
12effe625aScgd	* RCS IDS
13effe625aScgd	* COMPILATION FLAGS
14effe625aScgd	* MACRO DEFINITIONS
15effe625aScgd	* BLOCKS AND EXPRESSIONS
16effe625aScgd
17effe625aScgd
18effe625aScgdINCLUDE FILES
19effe625aScgd
209db8b601Sthorpej(1) All option headers should be included first, and sorted, like:
219db8b601Sthorpej
229db8b601Sthorpej#include "opt_dec_3000_300.h"
239db8b601Sthorpej#include "opt_dec_3000_500.h"
249db8b601Sthorpej
259db8b601Sthorpej(2) All C sources should include <sys/cdefs.h> as the first header to
269db8b601Sthorpejbe included after any option headers, with a line like:
27effe625aScgd
28effe625aScgd#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
29effe625aScgd
30effe625aScgd
31effe625aScgdRCS IDS
32effe625aScgd
33*77a6b82bSgehenna(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
34effe625aScgdappear at the top of the file in a single-line comment of the form
35effe625aScgd
36*77a6b82bSgehenna/*<space>$NetBSD: STYLE,v 1.7 2002/09/06 13:18:43 gehenna Exp $<space>*/
37effe625aScgd
38effe625aScgdwhich differs from the normal NetBSD style, in that it uses spaces
39a9356936Swizrather than tabs to separate the tag from the comment start and end
40effe625aScgddelimiters.
41effe625aScgd
4225ba9df3Scgd(2) All C and assembler sources should include an RCS ID tag which can
4325ba9df3Scgdbe compiled into the binary, with a line like:
44effe625aScgd
45*77a6b82bSgehenna__KERNEL_RCSID(0, "$NetBSD: STYLE,v 1.7 2002/09/06 13:18:43 gehenna Exp $");
46effe625aScgd
4725ba9df3Scgdafter the inclusion of cdefs.h.  Source files which include other source
4825ba9df3Scgdfiles should change the number '0' to a different number, so that it
49c244b23bSwizdoesn't conflict with the RCS ID definitions in included sources.
5025ba9df3ScgdGeneration of these RCS IDs is disabled if the kernel option
5125ba9df3ScgdNO_KERNEL_RCSIDS is defined.  (In some cases, picking the number to use
5225ba9df3Scgdmay not be so straightforward, but the rule above usually works.)
53effe625aScgd
54effe625aScgd
55effe625aScgdCOMPILATION FLAGS
56effe625aScgd
57effe625aScgdBy default, NetBSD/alpha kernel files are compiled with the following gcc
58effe625aScgdwarning flags:
59effe625aScgd
60effe625aScgd	-Werror
61effe625aScgd	-Wall
62effe625aScgd	-Wstrict-prototypes
63effe625aScgd	-Wmissing-prototypes
64effe625aScgd	-Wno-format
65effe625aScgd
66effe625aScgdNetBSD/alpha kernel code should compile cleanly with those flags.  At some
67effe625aScgdpoint in the future (when the nonstandard extensions have been removed
68effe625aScgdfrom the kernel printf() function), -Wformat will be re-enabled, so sources
69effe625aScgdshould be able to compile with it enabled as well.
70effe625aScgd
71effe625aScgd
72effe625aScgdMACRO DEFINITIONS
73effe625aScgd
74effe625aScgd(1) Macros which use C blocks (i.e. are of the form "{ ... expressions
75effe625aScgd... }") should always be defined like:
76effe625aScgd
77effe625aScgd#define	MACRO(arg1, arg2, argN)					\
78effe625aScgddo {								\
79effe625aScgd	...							\
80effe625aScgd	expressions						\
81effe625aScgd	...							\
82effe625aScgd} while (0)
83effe625aScgd
84effe625aScgdso that they behave like functions or macros which don't use blocks (e.g.
85effe625aScgdfor the purpose of "if (foo) MACRO(); else ...").
86effe625aScgd
87effe625aScgd
88effe625aScgdBLOCKS AND EXPRESSIONS
89effe625aScgd
90effe625aScgd(1) Surround blocks with { and } more often than is absolutely necessary.
91effe625aScgdFor instance:
92effe625aScgd
93effe625aScgd	if (foo)
94effe625aScgd		bar();
95effe625aScgd
96effe625aScgdis acceptable, but:
97effe625aScgd
98effe625aScgd	if (foo) {
99effe625aScgd		bar();
100effe625aScgd	}
101effe625aScgd
102effe625aScgdis preferred.  (In contrast, NetBSD KNF says that no braces are to be
103effe625aScgdused for control statements with zero or one statements.)
104effe625aScgd
105effe625aScgd(2) Use extra parentheses when it makes expressions clearer.  For instance,
106effe625aScgd
107effe625aScgd	(foo == 10 && bar == 20)
108effe625aScgd
109effe625aScgdis acceptable, but:
110effe625aScgd
111effe625aScgd	((foo == 10) && (bar == 20))
112effe625aScgd
113effe625aScgdis preferred.  (In contrast, NetBSD KNF says to avoid using parentheses
114effe625aScgdexcept where necessary unless the expression is very confusing without
115effe625aScgdthem.)
116