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