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