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