STYLE revision 1.1
11.1Scgd$NetBSD: STYLE,v 1.1 1997/04/07 23:57:10 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.1Scgd(1) NetBSD RCS ID tags ($NetBSD: STYLE,v 1.1 1997/04/07 23:57:10 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.1Scgd/*<space>$NetBSD: STYLE,v 1.1 1997/04/07 23:57:10 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.1Scgd(2) All C sources should include an RCS ID tag which can be compiled into
501.1Scgdthe binary, with a line like:
511.1Scgd
521.1Scgd__KERNEL_RCSID(0, "$NetBSD: STYLE,v 1.1 1997/04/07 23:57:10 cgd Exp $");
531.1Scgd
541.1Scgdafter the inclusion of cdefs.h.  C sources which include other C sources
551.1Scgdshould change the number '0' to a different number, so that it doesn't
561.1Scgdconflict with the RCS ID definitios in included sources.  Generation
571.1Scgdof these RCS IDs is disabled if the kernel option NO_KERNEL_RCSIDS is
581.1Scgddefined.
591.1Scgd
601.1Scgd
611.1ScgdCOMPILATION FLAGS
621.1Scgd
631.1ScgdBy default, NetBSD/alpha kernel files are compiled with the following gcc
641.1Scgdwarning flags:
651.1Scgd
661.1Scgd	-Werror
671.1Scgd	-Wall
681.1Scgd	-Wstrict-prototypes
691.1Scgd	-Wmissing-prototypes
701.1Scgd	-Wno-format
711.1Scgd
721.1ScgdNetBSD/alpha kernel code should compile cleanly with those flags.  At some
731.1Scgdpoint in the future (when the nonstandard extensions have been removed
741.1Scgdfrom the kernel printf() function), -Wformat will be re-enabled, so sources
751.1Scgdshould be able to compile with it enabled as well.
761.1Scgd
771.1Scgd
781.1ScgdMACRO DEFINITIONS
791.1Scgd
801.1Scgd(1) Macros which use C blocks (i.e. are of the form "{ ... expressions
811.1Scgd... }") should always be defined like:
821.1Scgd
831.1Scgd#define	MACRO(arg1, arg2, argN)					\
841.1Scgddo {								\
851.1Scgd	...							\
861.1Scgd	expressions						\
871.1Scgd	...							\
881.1Scgd} while (0)
891.1Scgd
901.1Scgdso that they behave like functions or macros which don't use blocks (e.g.
911.1Scgdfor the purpose of "if (foo) MACRO(); else ...").
921.1Scgd
931.1Scgd
941.1ScgdBLOCKS AND EXPRESSIONS
951.1Scgd
961.1Scgd(1) Surround blocks with { and } more often than is absolutely necessary.
971.1ScgdFor instance:
981.1Scgd
991.1Scgd	if (foo)
1001.1Scgd		bar();
1011.1Scgd
1021.1Scgdis acceptable, but:
1031.1Scgd
1041.1Scgd	if (foo) {
1051.1Scgd		bar();
1061.1Scgd	}
1071.1Scgd
1081.1Scgdis preferred.  (In contrast, NetBSD KNF says that no braces are to be
1091.1Scgdused for control statements with zero or one statements.)
1101.1Scgd
1111.1Scgd(2) Use extra parentheses when it makes expressions clearer.  For instance,
1121.1Scgd
1131.1Scgd	(foo == 10 && bar == 20)
1141.1Scgd
1151.1Scgdis acceptable, but:
1161.1Scgd
1171.1Scgd	((foo == 10) && (bar == 20))
1181.1Scgd
1191.1Scgdis preferred.  (In contrast, NetBSD KNF says to avoid using parentheses
1201.1Scgdexcept where necessary unless the expression is very confusing without
1211.1Scgdthem.)
122