11.7Sgehenna$NetBSD: STYLE,v 1.7 2002/09/06 13:18:43 gehenna 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.4Sthorpej(1) All option headers should be included first, and sorted, like:
211.4Sthorpej
221.4Sthorpej#include "opt_dec_3000_300.h"
231.4Sthorpej#include "opt_dec_3000_500.h"
241.4Sthorpej
251.4Sthorpej(2) All C sources should include <sys/cdefs.h> as the first header to
261.4Sthorpejbe included after any option headers, with a line like:
271.1Scgd
281.1Scgd#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
291.1Scgd
301.1Scgd
311.1ScgdRCS IDS
321.1Scgd
331.7Sgehenna(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
341.1Scgdappear at the top of the file in a single-line comment of the form
351.1Scgd
361.7Sgehenna/*<space>$NetBSD: STYLE,v 1.7 2002/09/06 13:18:43 gehenna Exp $<space>*/
371.1Scgd
381.1Scgdwhich differs from the normal NetBSD style, in that it uses spaces
391.5Swizrather than tabs to separate the tag from the comment start and end
401.1Scgddelimiters.
411.1Scgd
421.2Scgd(2) All C and assembler sources should include an RCS ID tag which can
431.2Scgdbe compiled into the binary, with a line like:
441.1Scgd
451.7Sgehenna__KERNEL_RCSID(0, "$NetBSD: STYLE,v 1.7 2002/09/06 13:18:43 gehenna Exp $");
461.1Scgd
471.2Scgdafter the inclusion of cdefs.h.  Source files which include other source
481.2Scgdfiles should change the number '0' to a different number, so that it
491.6Swizdoesn't conflict with the RCS ID definitions in included sources.
501.2ScgdGeneration of these RCS IDs is disabled if the kernel option
511.2ScgdNO_KERNEL_RCSIDS is defined.  (In some cases, picking the number to use
521.2Scgdmay not be so straightforward, but the rule above usually works.)
531.1Scgd
541.1Scgd
551.1ScgdCOMPILATION FLAGS
561.1Scgd
571.1ScgdBy default, NetBSD/alpha kernel files are compiled with the following gcc
581.1Scgdwarning flags:
591.1Scgd
601.1Scgd	-Werror
611.1Scgd	-Wall
621.1Scgd	-Wstrict-prototypes
631.1Scgd	-Wmissing-prototypes
641.1Scgd	-Wno-format
651.1Scgd
661.1ScgdNetBSD/alpha kernel code should compile cleanly with those flags.  At some
671.1Scgdpoint in the future (when the nonstandard extensions have been removed
681.1Scgdfrom the kernel printf() function), -Wformat will be re-enabled, so sources
691.1Scgdshould be able to compile with it enabled as well.
701.1Scgd
711.1Scgd
721.1ScgdMACRO DEFINITIONS
731.1Scgd
741.1Scgd(1) Macros which use C blocks (i.e. are of the form "{ ... expressions
751.1Scgd... }") should always be defined like:
761.1Scgd
771.1Scgd#define	MACRO(arg1, arg2, argN)					\
781.1Scgddo {								\
791.1Scgd	...							\
801.1Scgd	expressions						\
811.1Scgd	...							\
821.1Scgd} while (0)
831.1Scgd
841.1Scgdso that they behave like functions or macros which don't use blocks (e.g.
851.1Scgdfor the purpose of "if (foo) MACRO(); else ...").
861.1Scgd
871.1Scgd
881.1ScgdBLOCKS AND EXPRESSIONS
891.1Scgd
901.1Scgd(1) Surround blocks with { and } more often than is absolutely necessary.
911.1ScgdFor instance:
921.1Scgd
931.1Scgd	if (foo)
941.1Scgd		bar();
951.1Scgd
961.1Scgdis acceptable, but:
971.1Scgd
981.1Scgd	if (foo) {
991.1Scgd		bar();
1001.1Scgd	}
1011.1Scgd
1021.1Scgdis preferred.  (In contrast, NetBSD KNF says that no braces are to be
1031.1Scgdused for control statements with zero or one statements.)
1041.1Scgd
1051.1Scgd(2) Use extra parentheses when it makes expressions clearer.  For instance,
1061.1Scgd
1071.1Scgd	(foo == 10 && bar == 20)
1081.1Scgd
1091.1Scgdis acceptable, but:
1101.1Scgd
1111.1Scgd	((foo == 10) && (bar == 20))
1121.1Scgd
1131.1Scgdis preferred.  (In contrast, NetBSD KNF says to avoid using parentheses
1141.1Scgdexcept where necessary unless the expression is very confusing without
1151.1Scgdthem.)
116