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