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