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