STYLE revision 1.5
11.5Swiz$NetBSD: STYLE,v 1.5 2001/07/22 13:34:02 wiz 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.4Sthorpej(3) Nothing should include <sys/conf.h> directly. Instead, <machine/conf.h> 311.1Scgdshould be included. It includes <sys/conf.h> and provides appropriate 321.1Scgddefinitions for the machine-dependent devices and macros used by the Alpha 331.1Scgdport. 341.1Scgd 351.1Scgd 361.1ScgdRCS IDS 371.1Scgd 381.5Swiz(1) NetBSD RCS ID tags ($NetBSD: STYLE,v 1.5 2001/07/22 13:34:02 wiz Exp $ tags) in C sources and headers should 391.1Scgdappear at the top of the file in a single-line comment of the form 401.1Scgd 411.5Swiz/*<space>$NetBSD: STYLE,v 1.5 2001/07/22 13:34:02 wiz Exp $<space>*/ 421.1Scgd 431.1Scgdwhich differs from the normal NetBSD style, in that it uses spaces 441.5Swizrather than tabs to separate the tag from the comment start and end 451.1Scgddelimiters. 461.1Scgd 471.2Scgd(2) All C and assembler sources should include an RCS ID tag which can 481.2Scgdbe compiled into the binary, with a line like: 491.1Scgd 501.5Swiz__KERNEL_RCSID(0, "$NetBSD: STYLE,v 1.5 2001/07/22 13:34:02 wiz Exp $"); 511.1Scgd 521.2Scgdafter the inclusion of cdefs.h. Source files which include other source 531.2Scgdfiles should change the number '0' to a different number, so that it 541.2Scgddoesn't conflict with the RCS ID definitios in included sources. 551.2ScgdGeneration of these RCS IDs is disabled if the kernel option 561.2ScgdNO_KERNEL_RCSIDS is defined. (In some cases, picking the number to use 571.2Scgdmay not be so straightforward, but the rule above usually works.) 581.1Scgd 591.1Scgd 601.1ScgdCOMPILATION FLAGS 611.1Scgd 621.1ScgdBy default, NetBSD/alpha kernel files are compiled with the following gcc 631.1Scgdwarning flags: 641.1Scgd 651.1Scgd -Werror 661.1Scgd -Wall 671.1Scgd -Wstrict-prototypes 681.1Scgd -Wmissing-prototypes 691.1Scgd -Wno-format 701.1Scgd 711.1ScgdNetBSD/alpha kernel code should compile cleanly with those flags. At some 721.1Scgdpoint in the future (when the nonstandard extensions have been removed 731.1Scgdfrom the kernel printf() function), -Wformat will be re-enabled, so sources 741.1Scgdshould be able to compile with it enabled as well. 751.1Scgd 761.1Scgd 771.1ScgdMACRO DEFINITIONS 781.1Scgd 791.1Scgd(1) Macros which use C blocks (i.e. are of the form "{ ... expressions 801.1Scgd... }") should always be defined like: 811.1Scgd 821.1Scgd#define MACRO(arg1, arg2, argN) \ 831.1Scgddo { \ 841.1Scgd ... \ 851.1Scgd expressions \ 861.1Scgd ... \ 871.1Scgd} while (0) 881.1Scgd 891.1Scgdso that they behave like functions or macros which don't use blocks (e.g. 901.1Scgdfor the purpose of "if (foo) MACRO(); else ..."). 911.1Scgd 921.1Scgd 931.1ScgdBLOCKS AND EXPRESSIONS 941.1Scgd 951.1Scgd(1) Surround blocks with { and } more often than is absolutely necessary. 961.1ScgdFor instance: 971.1Scgd 981.1Scgd if (foo) 991.1Scgd bar(); 1001.1Scgd 1011.1Scgdis acceptable, but: 1021.1Scgd 1031.1Scgd if (foo) { 1041.1Scgd bar(); 1051.1Scgd } 1061.1Scgd 1071.1Scgdis preferred. (In contrast, NetBSD KNF says that no braces are to be 1081.1Scgdused for control statements with zero or one statements.) 1091.1Scgd 1101.1Scgd(2) Use extra parentheses when it makes expressions clearer. For instance, 1111.1Scgd 1121.1Scgd (foo == 10 && bar == 20) 1131.1Scgd 1141.1Scgdis acceptable, but: 1151.1Scgd 1161.1Scgd ((foo == 10) && (bar == 20)) 1171.1Scgd 1181.1Scgdis preferred. (In contrast, NetBSD KNF says to avoid using parentheses 1191.1Scgdexcept where necessary unless the expression is very confusing without 1201.1Scgdthem.) 121