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