]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/style.9
This commit was generated by cvs2svn to compensate for changes in r133931,
[FreeBSD/FreeBSD.git] / share / man / man9 / style.9
1 .\" Copyright (c) 1995-2001 FreeBSD Inc.
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL [your name] OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .\"
26 .Dd December 7, 2001
27 .Dt STYLE 9
28 .Os
29 .Sh NAME
30 .Nm style
31 .Nd "kernel source file style guide"
32 .Sh DESCRIPTION
33 This file specifies the preferred style for kernel source files in the
34 .Fx
35 source tree.
36 It is also a guide for the preferred userland code style.
37 Many of the style rules are implicit in the examples.
38 Be careful to check the examples before assuming that
39 .Nm
40 is silent on an issue.
41 .Bd -literal
42 /*
43  * Style guide for FreeBSD.  Based on the CSRG's KNF (Kernel Normal Form).
44  *
45  *      @(#)style       1.14 (Berkeley) 4/28/95
46  * $FreeBSD$
47  */
48
49 /*
50  * VERY important single-line comments look like this.
51  */
52
53 /* Most single-line comments look like this. */
54
55 /*
56  * Multi-line comments look like this.  Make them real sentences.  Fill
57  * them so they look like real paragraphs.
58  */
59 .Ed
60 .Pp
61 After any copyright header, there is a blank line, and the
62 .Va rcsid
63 for source files.
64 Version control system ID tags should only exist once in a file
65 (unlike in this one).
66 Non-C/C++ source files follow the example above, while C/C++ source files
67 follow the one below.
68 All VCS (version control system) revision identification in files obtained
69 from elsewhere should be maintained, including, where applicable, multiple IDs
70 showing a file's history.
71 In general, do not edit foreign IDs or their infrastructure.
72 Unless otherwise wrapped (such as
73 .Dq Li "#if defined(LIBC_SCCS)" ) ,
74 enclose both in
75 .Dq Li "#if 0 ... #endif"
76 to hide any uncompilable bits
77 and to keep the IDs out of object files.
78 Only add
79 .Dq Li "From: "
80 in front of foreign VCS IDs if the file is renamed.
81 .Bd -literal
82 #if 0
83 #ifndef lint
84 static char sccsid[] = "@(#)style       1.14 (Berkeley) 4/28/95";
85 #endif /* not lint */
86 #endif
87
88 #include <sys/cdefs.h>
89 __FBSDID("$FreeBSD$");
90 .Ed
91 .Pp
92 Leave another blank line before the header files.
93 .Pp
94 Kernel include files (i.e.\&
95 .Pa sys/*.h )
96 come first; normally, include
97 .In sys/types.h
98 OR
99 .In sys/param.h ,
100 but not both.
101 .In sys/types.h
102 includes
103 .In sys/cdefs.h ,
104 and it is okay to depend on that.
105 .Bd -literal
106 #include <sys/types.h>  /* Non-local includes in angle brackets. */
107 .Ed
108 .Pp
109 For a network program, put the network include files next.
110 .Bd -literal
111 #include <net/if.h>
112 #include <net/if_dl.h>
113 #include <net/route.h>
114 #include <netinet/in.h>
115 #include <protocols/rwhod.h>
116 .Ed
117 .Pp
118 Do not use files in
119 .Pa /usr/include
120 for files in the kernel.
121 .Pp
122 Leave a blank line before the next group, the
123 .Pa /usr/include
124 files,
125 which should be sorted alphabetically by name.
126 .Bd -literal
127 #include <stdio.h>
128 .Ed
129 .Pp
130 Global pathnames are defined in
131 .In paths.h .
132 Pathnames local
133 to the program go in
134 .Qq Pa pathnames.h
135 in the local directory.
136 .Bd -literal
137 #include <paths.h>
138 .Ed
139 .Pp
140 Leave another blank line before the user include files.
141 .Bd -literal
142 #include "pathnames.h"          /* Local includes in double quotes. */
143 .Ed
144 .Pp
145 Do not
146 .Ic #define
147 or declare names in the implementation namespace except
148 for implementing application interfaces.
149 .Pp
150 The names of
151 .Dq unsafe
152 macros (ones that have side effects), and the names of macros for
153 manifest constants, are all in uppercase.
154 The expansions of expression-like macros are either a single token
155 or have outer parentheses.
156 Put a single tab character between the
157 .Ic #define
158 and the macro name.
159 If a macro is an inline expansion of a function, the function name is
160 all in lowercase and the macro has the same name all in uppercase.
161 .\" XXX the above conflicts with ANSI style where the names are the
162 .\" same and you #undef the macro (if any) to get the function.
163 .\" It is not followed for MALLOC(), and not very common if inline
164 .\" functions are used.
165 Right-justify the
166 backslashes; it makes it easier to read.
167 If the macro encapsulates a compound statement, enclose it in a
168 .Ic do
169 loop,
170 so that it can safely be used in
171 .Ic if
172 statements.
173 Any final statement-terminating semicolon should be
174 supplied by the macro invocation rather than the macro, to make parsing easier
175 for pretty-printers and editors.
176 .Bd -literal
177 #define MACRO(x, y) do {                                                \e
178         variable = (x) + (y);                                           \e
179         (y) += 2;                                                       \e
180 } while (0)
181 .Ed
182 .Pp
183 When code is conditionally compiled using
184 .Ic #ifdef
185 or
186 .Ic #if ,
187 a comment may be added following the matching
188 .Ic #endif
189 or
190 .Ic #else
191 to permit the reader to easily discern where conditionally compiled code
192 regions end.
193 This comment should be used only for (subjectively) long regions, regions
194 greater than 20 lines, or where a series of nested
195 .Ic #ifdef 's
196 may be confusing to the reader.
197 Exceptions may be made for cases where code is conditionally not compiled for
198 the purposes of
199 .Xr lint 1 ,
200 even though the uncompiled region may be small.
201 The comment should be separated from the
202 .Ic #endif
203 or
204 .Ic #else
205 by a single space.
206 For short conditionally compiled regions, a closing comment should not be
207 used.
208 .Pp
209 The comment for
210 .Ic #endif
211 should match the expression used in the corresponding
212 .Ic #if
213 or
214 .Ic #ifdef .
215 The comment for
216 .Ic #else
217 and
218 .Ic #elif
219 should match the inverse of the expression(s) used in the preceding
220 .Ic #if
221 and/or
222 .Ic #elif
223 statements.
224 In the comments, the subexpression
225 .Dq Li defined(FOO)
226 is abbreviated as
227 .Dq Li FOO .
228 For the purposes of comments,
229 .Dq Ic #ifndef Li FOO
230 is treated as
231 .Dq Ic #if Li !defined(FOO) .
232 .Bd -literal
233 #ifdef KTRACE
234 #include <sys/ktrace.h>
235 #endif
236
237 #ifdef COMPAT_43
238 /* A large region here, or other conditional code. */
239 #else /* !COMPAT_43 */
240 /* Or here. */
241 #endif /* COMPAT_43 */
242
243 #ifndef COMPAT_43
244 /* Yet another large region here, or other conditional code. */
245 #else /* COMPAT_43 */
246 /* Or here. */
247 #endif /* !COMPAT_43 */
248 .Ed
249 .Pp
250 The project is slowly moving to use the
251 .St -isoC-99
252 unsigned integer identifiers of the form
253 .Vt uintXX_t
254 in preference to the older
255 .Bx Ns -style
256 integer identifiers of the form
257 .Vt u_intXX_t .
258 New code should use the former, and old code should be converted to
259 the new form if other major work is being done in that area and
260 there is no overriding reason to prefer the older
261 .Bx Ns -style .
262 Like white-space commits, care should be taken in making
263 .Vt uintXX_t
264 only commits.
265 .Pp
266 Enumeration values are all uppercase.
267 .Bd -literal
268 enum enumtype { ONE, TWO } et;
269 .Ed
270 .Pp
271 In declarations, do not put any whitespace between asterisks and
272 adjacent tokens, except for tokens that are identifiers related to
273 types.
274 (These identifiers are the names of basic types, type
275 qualifiers, and
276 .Ic typedef Ns -names
277 other than the one being declared.)
278 Separate these identifiers from asterisks using a single space.
279 .Pp
280 When declaring variables in structures, declare them sorted by use, then
281 by size, and then in alphabetical order.
282 The first category normally does not apply, but there are exceptions.
283 Each one gets its own line.
284 Try to make the structure
285 readable by aligning the member names using either one or two tabs
286 depending upon your judgment.
287 You should use one tab only if it suffices to align at least 90% of
288 the member names.
289 Names following extremely long types
290 should be separated by a single space.
291 .Pp
292 Major structures should be declared at the top of the file in which they
293 are used, or in separate header files if they are used in multiple
294 source files.
295 Use of the structures should be by separate declarations
296 and should be
297 .Ic extern
298 if they are declared in a header file.
299 .Bd -literal
300 struct foo {
301         struct foo      *next;          /* List of active foo. */
302         struct mumble   amumble;        /* Comment for mumble. */
303         int             bar;            /* Try to align the comments. */
304         struct verylongtypename *baz;   /* Won't fit in 2 tabs. */
305 };
306 struct foo *foohead;                    /* Head of global foo list. */
307 .Ed
308 .Pp
309 Use
310 .Xr queue 3
311 macros rather than rolling your own lists, whenever possible.
312 Thus,
313 the previous example would be better written:
314 .Bd -literal
315 #include <sys/queue.h>
316
317 struct foo {
318         LIST_ENTRY(foo) link;           /* Use queue macros for foo lists. */
319         struct mumble   amumble;        /* Comment for mumble. */
320         int             bar;            /* Try to align the comments. */
321         struct verylongtypename *baz;   /* Won't fit in 2 tabs. */
322 };
323 LIST_HEAD(, foo) foohead;               /* Head of global foo list. */
324 .Ed
325 .Pp
326 Avoid using typedefs for structure types.
327 Typedefs are problematic because they do not properly hide their
328 underlying type; for example you need to know if the typedef is
329 the structure itself or a pointer to the structure.
330 In addition they must be declared exactly once, whereas an
331 incomplete structure type can be mentioned as many times as
332 necessary.
333 Typedefs are difficult to use in stand-alone header files:
334 the header that defines the typedef must be included
335 before the header that uses it, or by the header that uses
336 it (which causes namespace pollution), or there must be a
337 back-door mechanism for obtaining the typedef.
338 .Pp
339 When convention requires a
340 .Ic typedef ,
341 make its name match the struct tag.
342 Avoid typedefs ending in
343 .Dq Li _t ,
344 except as specified in Standard C or by
345 .Tn POSIX .
346 .Bd -literal
347 /* Make the structure name match the typedef. */
348 typedef struct bar {
349         int     level;
350 } BAR;
351 typedef int             foo;            /* This is foo. */
352 typedef const long      baz;            /* This is baz. */
353 .Ed
354 .Pp
355 All functions are prototyped somewhere.
356 .Pp
357 Function prototypes for private functions (i.e., functions not used
358 elsewhere) go at the top of the first source module.
359 Functions
360 local to one source module should be declared
361 .Ic static .
362 .Pp
363 Functions used from other parts of the kernel are prototyped in the
364 relevant include file.
365 Function prototypes should be listed in a logical order, preferably
366 alphabetical unless there is a compelling reason to use a different
367 ordering.
368 .Pp
369 Functions that are used locally in more than one module go into a
370 separate header file, e.g.\&
371 .Qq Pa extern.h .
372 .Pp
373 Do not use the
374 .Dv __P
375 macro.
376 .Pp
377 In general code can be considered
378 .Dq "new code"
379 when it makes up about 50% or more of the file(s) involved.
380 This is enough
381 to break precedents in the existing code and use the current
382 .Nm
383 guidelines.
384 .Pp
385 The kernel has a name associated with parameter types, e.g., in the kernel
386 use:
387 .Bd -literal
388 void    function(int fd);
389 .Ed
390 .Pp
391 In header files visible to userland applications, prototypes that are
392 visible must use either
393 .Dq protected
394 names (ones beginning with an underscore)
395 or no names with the types.
396 It is preferable to use protected names.
397 E.g., use:
398 .Bd -literal
399 void    function(int);
400 .Ed
401 .Pp
402 or:
403 .Bd -literal
404 void    function(int _fd);
405 .Ed
406 .Pp
407 Prototypes may have an extra space after a tab to enable function names
408 to line up:
409 .Bd -literal
410 static char     *function(int _arg, const char *_arg2, struct foo *_arg3,
411                     struct bar *_arg4);
412 static void      usage(void);
413
414 /*
415  * All major routines should have a comment briefly describing what
416  * they do.  The comment before the "main" routine should describe
417  * what the program does.
418  */
419 int
420 main(int argc, char *argv[])
421 {
422         char *ep;
423         long num;
424         int ch;
425 .Ed
426 .Pp
427 For consistency,
428 .Xr getopt 3
429 should be used to parse options.
430 Options
431 should be sorted in the
432 .Xr getopt 3
433 call and the
434 .Ic switch
435 statement, unless
436 parts of the
437 .Ic switch
438 cascade.
439 Elements in a
440 .Ic switch
441 statement that cascade should have a
442 .Li FALLTHROUGH
443 comment.
444 Numerical arguments should be checked for accuracy.
445 Code that cannot be reached should have a
446 .Li NOTREACHED
447 comment.
448 .Bd -literal
449         while ((ch = getopt(argc, argv, "abNn:")) != -1)
450                 switch (ch) {           /* Indent the switch. */
451                 case 'a':               /* Don't indent the case. */
452                         aflag = 1;
453                         /* FALLTHROUGH */
454                 case 'b':
455                         bflag = 1;
456                         break;
457                 case 'N':
458                         Nflag = 1;
459                         break;
460                 case 'n':
461                         num = strtol(optarg, &ep, 10);
462                         if (num <= 0 || *ep != '\e0') {
463                                 warnx("illegal number, -n argument -- %s",
464                                     optarg);
465                                 usage();
466                         }
467                         break;
468                 case '?':
469                 default:
470                         usage();
471                         /* NOTREACHED */
472                 }
473         argc -= optind;
474         argv += optind;
475 .Ed
476 .Pp
477 Space after keywords
478 .Pq Ic if , while , for , return , switch .
479 No braces
480 .Ql ( \&{
481 and
482 .Ql \&} )
483 are
484 used for control statements with zero or only a single statement unless that
485 statement is more than a single line in which case they are permitted.
486 Forever loops are done with
487 .Ic for Ns 's ,
488 not
489 .Ic while Ns 's .
490 .Bd -literal
491         for (p = buf; *p != '\e0'; ++p)
492                 ;       /* nothing */
493         for (;;)
494                 stmt;
495         for (;;) {
496                 z = a + really + long + statement + that + needs +
497                     two + lines + gets + indented + four + spaces +
498                     on + the + second + and + subsequent + lines;
499         }
500         for (;;) {
501                 if (cond)
502                         stmt;
503         }
504         if (val != NULL)
505                 val = realloc(val, newsize);
506 .Ed
507 .Pp
508 Parts of a
509 .Ic for
510 loop may be left empty.
511 Do not put declarations
512 inside blocks unless the routine is unusually complicated.
513 .Bd -literal
514         for (; cnt < 15; cnt++) {
515                 stmt1;
516                 stmt2;
517         }
518 .Ed
519 .Pp
520 Indentation is an 8 character tab.
521 Second level indents are four spaces.
522 If you have to wrap a long statement, put the operator at the end of the
523 line.
524 .Bd -literal
525         while (cnt < 20 && this_variable_name_is_too_long &&
526             ep != NULL)
527                 z = a + really + long + statement + that + needs +
528                     two + lines + gets + indented + four + spaces +
529                     on + the + second + and + subsequent + lines;
530 .Ed
531 .Pp
532 Do not add whitespace at the end of a line, and only use tabs
533 followed by spaces
534 to form the indentation.
535 Do not use more spaces than a tab will produce
536 and do not use spaces in front of tabs.
537 .Pp
538 Closing and opening braces go on the same line as the
539 .Ic else .
540 Braces that are not necessary may be left out.
541 .Bd -literal
542         if (test)
543                 stmt;
544         else if (bar) {
545                 stmt;
546                 stmt;
547         } else
548                 stmt;
549 .Ed
550 .Pp
551 No spaces after function names.
552 Commas have a space after them.
553 No spaces
554 after
555 .Ql \&(
556 or
557 .Ql \&[
558 or preceding
559 .Ql \&]
560 or
561 .Ql \&)
562 characters.
563 .Bd -literal
564         error = function(a1, a2);
565         if (error != 0)
566                 exit(error);
567 .Ed
568 .Pp
569 Unary operators do not require spaces, binary operators do.
570 Do not use parentheses unless they are required for precedence or unless the
571 statement is confusing without them.
572 Remember that other people may
573 confuse easier than you.
574 Do YOU understand the following?
575 .Bd -literal
576         a = b->c[0] + ~d == (e || f) || g && h ? i : j >> 1;
577         k = !(l & FLAGS);
578 .Ed
579 .Pp
580 Exits should be 0 on success, or according to the predefined
581 values in
582 .Xr sysexits 3 .
583 .Bd -literal
584         exit(EX_OK);    /*
585                          * Avoid obvious comments such as
586                          * "Exit 0 on success."
587                          */
588 }
589 .Ed
590 .Pp
591 The function type should be on a line by itself
592 preceding the function.
593 The opening brace of the function body should be
594 on a line by itself.
595 .Bd -literal
596 static char *
597 function(int a1, int a2, float fl, int a4)
598 {
599 .Ed
600 .Pp
601 When declaring variables in functions declare them sorted by size,
602 then in alphabetical order; multiple ones per line are okay.
603 If a line overflows reuse the type keyword.
604 .Pp
605 Be careful to not obfuscate the code by initializing variables in
606 the declarations.
607 Use this feature only thoughtfully.
608 DO NOT use function calls in initializers.
609 .Bd -literal
610         struct foo one, *two;
611         double three;
612         int *four, five;
613         char *six, seven, eight, nine, ten, eleven, twelve;
614
615         four = myfunction();
616 .Ed
617 .Pp
618 Do not declare functions inside other functions; ANSI C says that
619 such declarations have file scope regardless of the nesting of the
620 declaration.
621 Hiding file declarations in what appears to be a local
622 scope is undesirable and will elicit complaints from a good compiler.
623 .Pp
624 Casts and
625 .Ic sizeof Ns 's
626 are not followed by a space.
627 Note that
628 .Xr indent 1
629 does not understand this rule.
630 .Ic sizeof Ns 's
631 are written with parenthesis always.
632 The redundant parenthesis rules do not apply to
633 .Fn sizeof var
634 instances.
635 .Pp
636 .Dv NULL
637 is the preferred null pointer constant.
638 Use
639 .Dv NULL
640 instead of
641 .Vt ( "type *" ) Ns 0
642 or
643 .Vt ( "type *" ) Ns Dv NULL
644 in contexts where the compiler knows the
645 type, e.g., in assignments.
646 Use
647 .Vt ( "type *" ) Ns Dv NULL
648 in other contexts,
649 in particular for all function args.
650 (Casting is essential for
651 variadic args and is necessary for other args if the function prototype
652 might not be in scope.)
653 Test pointers against
654 .Dv NULL ,
655 e.g., use:
656 .Pp
657 .Bd -literal
658 (p = f()) == NULL
659 .Ed
660 .Pp
661 not:
662 .Bd -literal
663 !(p = f())
664 .Ed
665 .Pp
666 Do not use
667 .Ic \&!
668 for tests unless it is a boolean, e.g.\& use
669 .Bd -literal
670 if (*p == '\e0')
671 .Ed
672 .Pp
673 not
674 .Bd -literal
675 if (!*p)
676 .Ed
677 .Pp
678 Routines returning
679 .Vt "void *"
680 should not have their return values cast
681 to any pointer type.
682 .Pp
683 Values in
684 .Ic return
685 statements should be enclosed in parentheses.
686 .Pp
687 Use
688 .Xr err 3
689 or
690 .Xr warn 3 ,
691 do not roll your own.
692 .Bd -literal
693         if ((four = malloc(sizeof(struct foo))) == NULL)
694                 err(1, (char *)NULL);
695         if ((six = (int *)overflow()) == NULL)
696                 errx(1, "number overflowed");
697         return (eight);
698 }
699 .Ed
700 .Pp
701 Old-style function declarations look like this:
702 .Bd -literal
703 static char *
704 function(a1, a2, fl, a4)
705         int a1, a2;     /* Declare ints, too, don't default them. */
706         float fl;       /* Beware double vs. float prototype differences. */
707         int a4;         /* List in order declared. */
708 {
709 .Ed
710 .Pp
711 Use ANSI function declarations unless you explicitly need K&R compatibility.
712 Long parameter lists are wrapped with a normal four space indent.
713 .Pp
714 Variable numbers of arguments should look like this.
715 .Bd -literal
716 #include <stdarg.h>
717
718 void
719 vaf(const char *fmt, ...)
720 {
721         va_list ap;
722
723         va_start(ap, fmt);
724         STUFF;
725         va_end(ap);
726         /* No return needed for void functions. */
727 }
728
729 static void
730 usage()
731 {
732         /* Insert an empty line if the function has no local variables. */
733 .Ed
734 .Pp
735 Use
736 .Xr printf 3 ,
737 not
738 .Xr fputs 3 ,
739 .Xr puts 3 ,
740 .Xr putchar 3 ,
741 whatever; it is faster and usually cleaner, not
742 to mention avoiding stupid bugs.
743 .Pp
744 Usage statements should look like the manual pages
745 .Sx SYNOPSIS .
746 The usage statement should be structured in the following order:
747 .Bl -enum
748 .It
749 Options without operands come first,
750 in alphabetical order,
751 inside a single set of brackets
752 .Ql ( \&[
753 and
754 .Ql \&] ) .
755 .It
756 Options with operands come next,
757 also in alphabetical order,
758 with each option and its argument inside its own pair of brackets.
759 .It
760 Required arguments
761 (if any)
762 are next,
763 listed in the order they should be specified on the command line.
764 .It
765 Finally,
766 any optional arguments should be listed,
767 listed in the order they should be specified,
768 and all inside brackets.
769 .El
770 .Pp
771 A bar
772 .Pq Ql \&|
773 separates
774 .Dq either-or
775 options/arguments,
776 and multiple options/arguments which are specified together are
777 placed in a single set of brackets.
778 .Bd -literal -offset 4n
779 "usage: f [-aDde] [-b b_arg] [-m m_arg] req1 req2 [opt1 [opt2]]\en"
780 "usage: f [-a | -b] [-c [-dEe] [-n number]]\en"
781 .Ed
782 .Bd -literal
783         (void)fprintf(stderr, "usage: f [-ab]\en");
784         exit(EX_USAGE);
785 }
786 .Ed
787 .Pp
788 Note that the manual page options description should list the options in
789 pure alphabetical order.
790 That is, without regard to whether an option takes arguments or not.
791 The alphabetical ordering should take into account the case ordering
792 shown above.
793 .Pp
794 New core kernel code should be reasonably compliant with the
795 .Nm
796 guides.
797 The guidelines for third-party maintained modules and device drivers are more
798 relaxed but at a minimum should be internally consistent with their style.
799 .Pp
800 Stylistic changes (including whitespace changes) are hard on the source
801 repository and are to be avoided without good reason.
802 Code that is approximately
803 .Fx
804 KNF
805 .Nm
806 compliant in the repository must not diverge from compliance.
807 .Pp
808 Whenever possible, code should be run through a code checker
809 (e.g.,
810 .Xr lint 1
811 or
812 .Nm gcc Fl Wall )
813 and produce minimal warnings.
814 .Sh SEE ALSO
815 .Xr indent 1 ,
816 .Xr lint 1 ,
817 .Xr err 3 ,
818 .Xr sysexits 3 ,
819 .Xr warn 3 ,
820 .Xr style.Makefile 5
821 .Sh HISTORY
822 This man page is largely based on the
823 .Pa src/admin/style/style
824 file from the
825 .Bx 4.4 Lite2
826 release, with occasional updates to reflect the current practice and
827 desire of the
828 .Fx
829 project.