STYLE revision 1.2
11.2Scgd$NetBSD: STYLE,v 1.2 1997/04/08 00:18:25 cgd Exp $
21.1Scgd
31.1ScgdStyle guide for NetBSD/alpha kernel files.
41.1Scgd
51.1ScgdThis file is meant to supplement the NetBSD KNF style guide (which covers
61.1Scgdmost of the rest of the system, and can be found in /usr/share/misc/style).
71.1Scgd
81.1Scgd
91.1ScgdSECTIONS
101.1Scgd
111.1Scgd	* INCLUDE FILES
121.1Scgd	* RCS IDS
131.1Scgd	* COMPILATION FLAGS
141.1Scgd	* MACRO DEFINITIONS
151.1Scgd	* BLOCKS AND EXPRESSIONS
161.1Scgd
171.1Scgd
181.1ScgdINCLUDE FILES
191.1Scgd
201.1Scgd(1) All C and assembly sources (which are not included by other C or
211.1Scgdassembly sources) sources should include <machine/options.h> as the
221.1Scgdfirst header to be included, with a line like:
231.1Scgd
241.1Scgd#include <machine/options.h>		/* Pull in config options headers */
251.1Scgd
261.1Scgd(2) All C sources should include <sys/cdefs.h> (after <machine/options.h>,
271.1Scgdwhen it is included, otherwise as the first header to be included), with
281.1Scgda line like:
291.1Scgd
301.1Scgd#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
311.1Scgd
321.1Scgd(3) Nothing should include <sys/conf.h> directly.  Instead, <machine/conf.h>
331.1Scgdshould be included.  It includes <sys/conf.h> and provides appropriate
341.1Scgddefinitions for the machine-dependent devices and macros used by the Alpha
351.1Scgdport.
361.1Scgd
371.1Scgd
381.1ScgdRCS IDS
391.1Scgd
401.2Scgd(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
411.1Scgdappear at the top of the file in a single-line comment of the form
421.1Scgd
431.2Scgd/*<space>$NetBSD: STYLE,v 1.2 1997/04/08 00:18:25 cgd Exp $<space>*/
441.1Scgd
451.1Scgdwhich differs from the normal NetBSD style, in that it uses spaces
461.1Scgdrather than tabs to seperate the tag from the comment start and end
471.1Scgddelimiters.
481.1Scgd
491.2Scgd(2) All C and assembler sources should include an RCS ID tag which can
501.2Scgdbe compiled into the binary, with a line like:
511.1Scgd
521.2Scgd__KERNEL_RCSID(0, "$NetBSD: STYLE,v 1.2 1997/04/08 00:18:25 cgd Exp $");
531.1Scgd
541.2Scgdafter the inclusion of cdefs.h.  Source files which include other source
551.2Scgdfiles should change the number '0' to a different number, so that it
561.2Scgddoesn't conflict with the RCS ID definitios in included sources.
571.2ScgdGeneration of these RCS IDs is disabled if the kernel option
581.2ScgdNO_KERNEL_RCSIDS is defined.  (In some cases, picking the number to use
591.2Scgdmay not be so straightforward, but the rule above usually works.)
601.1Scgd
611.1Scgd
621.1ScgdCOMPILATION FLAGS
631.1Scgd
641.1ScgdBy default, NetBSD/alpha kernel files are compiled with the following gcc
651.1Scgdwarning flags:
661.1Scgd
671.1Scgd	-Werror
681.1Scgd	-Wall
691.1Scgd	-Wstrict-prototypes
701.1Scgd	-Wmissing-prototypes
711.1Scgd	-Wno-format
721.1Scgd
731.1ScgdNetBSD/alpha kernel code should compile cleanly with those flags.  At some
741.1Scgdpoint in the future (when the nonstandard extensions have been removed
751.1Scgdfrom the kernel printf() function), -Wformat will be re-enabled, so sources
761.1Scgdshould be able to compile with it enabled as well.
771.1Scgd
781.1Scgd
791.1ScgdMACRO DEFINITIONS
801.1Scgd
811.1Scgd(1) Macros which use C blocks (i.e. are of the form "{ ... expressions
821.1Scgd... }") should always be defined like:
831.1Scgd
841.1Scgd#define	MACRO(arg1, arg2, argN)					\
851.1Scgddo {								\
861.1Scgd	...							\
871.1Scgd	expressions						\
881.1Scgd	...							\
891.1Scgd} while (0)
901.1Scgd
911.1Scgdso that they behave like functions or macros which don't use blocks (e.g.
921.1Scgdfor the purpose of "if (foo) MACRO(); else ...").
931.1Scgd
941.1Scgd
951.1ScgdBLOCKS AND EXPRESSIONS
961.1Scgd
971.1Scgd(1) Surround blocks with { and } more often than is absolutely necessary.
981.1ScgdFor instance:
991.1Scgd
1001.1Scgd	if (foo)
1011.1Scgd		bar();
1021.1Scgd
1031.1Scgdis acceptable, but:
1041.1Scgd
1051.1Scgd	if (foo) {
1061.1Scgd		bar();
1071.1Scgd	}
1081.1Scgd
1091.1Scgdis preferred.  (In contrast, NetBSD KNF says that no braces are to be
1101.1Scgdused for control statements with zero or one statements.)
1111.1Scgd
1121.1Scgd(2) Use extra parentheses when it makes expressions clearer.  For instance,
1131.1Scgd
1141.1Scgd	(foo == 10 && bar == 20)
1151.1Scgd
1161.1Scgdis acceptable, but:
1171.1Scgd
1181.1Scgd	((foo == 10) && (bar == 20))
1191.1Scgd
1201.1Scgdis preferred.  (In contrast, NetBSD KNF says to avoid using parentheses
1211.1Scgdexcept where necessary unless the expression is very confusing without
1221.1Scgdthem.)
123