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