style.9.txt 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. STYLE(9)
  2. ========
  3. :doctype: manpage
  4. :man source: X15
  5. :man manual: X15 Kernel Developer{rsquo}s Manual
  6. NAME
  7. ----
  8. style - kernel coding style and rules
  9. DESCRIPTION
  10. -----------
  11. This document describes the preferred coding style for the X15 kernel,
  12. which is a close variant of the modern K&R style. It probably does not
  13. encompass all the rules, which are quite numerous despite efforts to
  14. keep them simple and compact. As a result, developers should compare
  15. their work against existing recent modules and infer the rules that
  16. may not be mentioned here. If you identify multiple rules that seem
  17. to conflict, assume any of them is valid. If in doubt, make a pragmatic
  18. decision and move forward.
  19. EXPLICIT PROGRAMMING
  20. --------------------
  21. As a general rule, the coding style for the X15 kernel emphasizes what
  22. could be called "explicit programming", which means that it encourages
  23. developers to clearly state their intent in the code itself. There are
  24. various ways to attempt that, and it can never be completely achieved,
  25. but it remains a strong guiding principle. For example, it is the main
  26. reason behind the adoption of the C programming language, despite its
  27. limitations, and object-oriented programming, despite the lack of support
  28. in the language.
  29. The price of explicit programming is verbosity. Correlations between
  30. code quantity and bugs do exist, and they form part of the motivation
  31. for more modern tools and languages, but such results merely hide the
  32. confounding variable behind the correlations : inadequate programming
  33. skills. Programming is a demanding activity, and kernel programming
  34. even more so. Reducing the number of bugs by writing less code is
  35. therefore not a robust strategy. Instead, developers should learn
  36. a set of good practices, one of them (hopefully) being described in
  37. this document. Since it is expected from developers that they spend
  38. most of their time and efforts designing their code, the ratio of the
  39. time spent writing code compared to the total development time should
  40. be low, from 5 to 30% most of the time. The increase in verbosity should
  41. therefore be close to negligible. On the other hand, the code should be
  42. very easy to understand and follow, which matters a lot more because
  43. there are a lot more people likely to read a piece of code compared
  44. to developers who have written that same piece of code. Besides, authors
  45. often find themselves in situations where they have forgotten the details
  46. of their own code and must understand it again.
  47. The environment around the X15 kernel closely adheres to the Unix culture.
  48. As a result, for developers with little or no experience with Unix, it is
  49. suggested to read {the-art-of-unix-programming} by Eric S. Raymond. Despite
  50. its age, it is still very relevant. The section "Basics of the Unix Philosophy"
  51. is of particular interest.
  52. LANGUAGES
  53. ---------
  54. The kernel is mostly written in the C programming language, conforming
  55. to ISO/IEC 9899:2011 (C11), with GNU extensions. While many GNU extensions
  56. are used, nested functions are forbidden. They are considered too specific
  57. to the GCC compiler. Note that X15 can currently be built with both GCC
  58. and Clang, and the latter has no support for nested functions. Also note
  59. that the kernel only expects the freestanding C environment from the compiler.
  60. Since X15 is low level system software, processor-specific assembly is
  61. inevitable. Developers should always refrain from writing assembly code
  62. when possible. Obviously, that code must only be used in
  63. architecture-specific modules.
  64. OBJECT-ORIENTED PROGRAMMING
  65. ---------------------------
  66. The X15 kernel is a set of functional modules which often implement
  67. objects. As a result, it naturally borrows some properties of
  68. object-oriented programming. Structures are used to define classes,
  69. and functions are used to implement methods, including constructors
  70. and destructors.
  71. Note however that only a subset of the object-oriented programming
  72. paradigm is applied. In particular, by choice more so than by technical
  73. lack, composition rather than inheritance is how code reuse is achieved,
  74. because inheritance is intrinsically implicit, which is against the
  75. general idea of explicit programming. In addition, polymorphic behaviour
  76. can also be achieved through abstract interfaces implemented with
  77. function pointer structures, an alternative which retains the property
  78. of being explicit to readers.
  79. The main purpose of OOP in X15 is to guide the structure of the code
  80. and data, so that developers have somewhat easy ways to determine how
  81. to group data together, assemble operations around them, and name them.
  82. Encapsulation naturally emerges as a side-effect of keeping interfaces
  83. as compact as possible. By restricting the selected practices of OOP,
  84. we get the banana, and the gorilla happily remains in the jungle.
  85. LINES
  86. -----
  87. Lines are normally limited to 80 columns, unless there is a compelling
  88. reason not to. This makes it easy to identify code with too many levels
  89. of indentation, and also allows comfortable viewing on small screens,
  90. including smartphones and tablets, as well as using multiple buffers
  91. side-by-side, which happens to also be convenient on larger screens.
  92. When defining a function, always break the line right before its name,
  93. so that qualifiers and the return type are on their own line. As a
  94. result, there is enough space for arguments even when the function
  95. name is long. It also makes functions easier to find with grep.
  96. Use at most one empty line as a separator. Use empty lines around
  97. functions and blocks, and also when you consider it appropriate
  98. inside blocks, e.g. to isolate critical sections, and/or locking
  99. functions.
  100. COMMENTS
  101. --------
  102. Each source file must start with a copyright statement comment,
  103. followed by a description of the file, unless the content is simple
  104. and obvious enough not to need one. The copyright statement and the
  105. description must be separated by two empty comment lines :
  106. [source,c]
  107. --------------------------------------------------------------------------------
  108. /*
  109. * Copyright (c) 2017 John Smith.
  110. *
  111. * This program is free software: you can redistribute it and/or modify
  112. * etc...
  113. *
  114. *
  115. * Description of the module.
  116. */
  117. --------------------------------------------------------------------------------
  118. Comments are written in C style, not C++. Here are a few examples :
  119. [source,c]
  120. --------------------------------------------------------------------------------
  121. /* Most single-line comments look like this */
  122. /*
  123. * Multi-line comments look like this. They should also be used for
  124. * "reference" descriptions in public headers.
  125. */
  126. struct dummy {
  127. int useless; /* Here is a way to provide short member descriptions */
  128. char moot; /* But don't hesitate to move descriptions above members
  129. when they spawn too many lines on the right side. */
  130. };
  131. /*
  132. * Instead of using C comments to disable code blocks, use the #if 0
  133. * preprocessor directive. Remember that C comments do not nest.
  134. */
  135. #if 0
  136. ...
  137. #endif
  138. --------------------------------------------------------------------------------
  139. Comments should not be abused. A large number of comments creates noise
  140. that readers must filter. Instead of writing a comment, ask yourself
  141. whether you can improve the meaning of the code itself, e.g. by changing
  142. names or breaking the code into smaller functions with names that are
  143. good enough to convey the message of the comment. Prefer to describe data
  144. over code. Comments in the code must point at details that are important
  145. and not obvious, and quality code should have few of those.
  146. Note that the project does not use an annotation format for documentation
  147. generation such as Doxygen, because, despite the undeniable improvement over
  148. other types of tools, the benefit still seems too small considering the
  149. additional rules that developers must keep in mind, the effort spent on
  150. checking the annotations and the duplication that they may cause, and the
  151. actual use of the generated documentation compared to direct source code
  152. browsing.
  153. INDENTATION
  154. -----------
  155. An indentation level is 4 spaces. It is strongly recommended, although
  156. not compulsory, to avoid using more than 3 indentation levels. More
  157. levels are tolerated for very short blocks. Combining 4 spaces per level
  158. with 80 columns allows the use of somewhat long, significant names, and
  159. naturally warns that a function should be simplified when the code becomes
  160. overly crammed to the right.
  161. Tabulation characters are strictly forbidden in source files, and should
  162. only be used in Makefiles where absolutely required. This allows everyone
  163. to get the same view, whatever the tools, including editors, comparison
  164. tools, web browsers, etc... It also removes the question of how to align
  165. lines in the code, e.g. when a function call spans multiple lines.
  166. In a switch statement, the case labels are aligned on the same column as
  167. the switch statement :
  168. [source,c]
  169. --------------------------------------------------------------------------------
  170. switch (var) {
  171. case VAL1:
  172. do_one_thing();
  173. break;
  174. case VAL2:
  175. case VAL3:
  176. do_another();
  177. break;
  178. }
  179. --------------------------------------------------------------------------------
  180. When conditions don't fit on a single line, break before operators,
  181. and indent the new line on the same column as the associated condition.
  182. Use parentheses to make precedence explicit, even when not strictly needed.
  183. Here is an example :
  184. [source,c]
  185. --------------------------------------------------------------------------------
  186. static void
  187. do_something(void)
  188. {
  189. if (overly_long_stupid_condition_name_that_you_shouldn_t_use
  190. && another_overly_long_stupid_condition_name
  191. && (yet_another_variable_with_an_overly_long_name
  192. || (a_first_long_variable_name != a_second_long_variable_name))) {
  193. return;
  194. }
  195. }
  196. --------------------------------------------------------------------------------
  197. One reason for those rules is to make reviews easier, by pushing code as much
  198. to the left as possible. The code should allow superficial reviews by just
  199. taking a quick look at the left side of the code, e.g. control statements,
  200. most conditions, operators, function names, their first parameter, etc...
  201. A line which reaches the right side marks a spot that may need more careful
  202. review.
  203. Don't write multiple statements on a single line.
  204. BRACES
  205. ------
  206. Opening braces are written at the end of lines containing control statements
  207. or struct/union/enum definitions. Closing braces are written on the same
  208. column as their associated control statement. Opening braces for functions
  209. are written on their own line after the arguments. Braces must also be used
  210. for single-line blocks, as this reduces both efforts when adding debugging
  211. code in such blocks and risks when merging conflicting code. In the case of
  212. multi-part statements, closing braces are written one the same line as the
  213. continuation. Here is an example :
  214. [source,c]
  215. --------------------------------------------------------------------------------
  216. void
  217. do_something(void *arg)
  218. {
  219. if (arg == NULL) {
  220. return;
  221. } else {
  222. print_what_it_is(arg);
  223. }
  224. do {
  225. play_with(arg);
  226. } while (can_play_with(arg));
  227. }
  228. --------------------------------------------------------------------------------
  229. The main reason for this style is that it allows line compression with
  230. almost no loss of readability, since it is easy to identify where blocks
  231. start.
  232. SPACES
  233. ------
  234. Spaces are used around most keywords. The exceptions are sizeof, typeof,
  235. alignof, and pass:[__attribute__], because of their similarity with
  236. functions. These exceptions must be used with parentheses. Spaces are also
  237. used around operators, except unary operators. For example :
  238. [source,c]
  239. --------------------------------------------------------------------------------
  240. if (!skip_copy && (memcmp(&a, &b, sizeof(a)) != 0)) {
  241. memcpy(&a, &b, sizeof(a));
  242. }
  243. --------------------------------------------------------------------------------
  244. When declaring pointer variables, use a space before "`*`", but not after,
  245. so that the "`*`" character and the variable name are adjacent. The main
  246. reason is that, while pointers are variables, with a type of their own,
  247. they are a special kind of variables, where the pointer nature is part
  248. of the variable, rather than just the type. Another is to reduce mistakes
  249. when declaring several variables on the same line. On the other hand, when
  250. writing functions returning pointers, use spaces both before and after
  251. "`*`". The reason is to always clearly separate returned types from the
  252. function name. Here is an example :
  253. [source,c]
  254. --------------------------------------------------------------------------------
  255. static struct my_type * my_function(struct my_type *var);
  256. /* ... */
  257. static struct my_type *
  258. my_function(struct my_type *var)
  259. {
  260. struct my_type *a, tmp;
  261. a = do_something(var, &tmp);
  262. return a;
  263. }
  264. --------------------------------------------------------------------------------
  265. Don't leave trailing spaces at the end of lines.
  266. NAMES
  267. -----
  268. First of all, use underscores instead of camel case to separate words
  269. in compound names. Function and variable names are in lower case. Macro
  270. names generally are in upper case, except for macros which behave
  271. strictly like functions and could be replaced with inline functions
  272. with no API change.
  273. There are two ways to name symbols, depending on whether they're global
  274. or not. Global symbols, either private (declared static) or public
  275. (part of the publically exposed interface), must always be prefixed with
  276. the namespace of the module they belong to. This makes it easy to know
  277. that a symbol is global and where to find it in the project. It also
  278. makes it possible to move definitions between the opaque implementation
  279. and header files with few diffs. Names for local variables should be
  280. short, with no prefixes, since prefixes are used to add context, and
  281. local variables are confined to the current context.
  282. When a module defines an object type, the type name immediately follows
  283. the module name. Functions applying to objects (methods) are named by
  284. adding the method name to the object type name. The name of helper
  285. functions and methods is simply added at the end of the main function
  286. that calls them.
  287. Here are some examples :
  288. [source,c]
  289. --------------------------------------------------------------------------------
  290. /*
  291. * Object type "cpu_pool" of module "kmem".
  292. */
  293. struct kmem_cpu_pool;
  294. /*
  295. * Method "init" of object type "cpu_pool" of module "kmem".
  296. */
  297. static void kmem_cpu_pool_init(struct kmem_cpu_pool *cpu_pool,
  298. struct kmem_cache *cache);
  299. /*
  300. * Object type "cache" of module "kmem".
  301. */
  302. struct kmem_cache;
  303. /*
  304. * Helper function "verify" of method "alloc" of object type "cache" of
  305. * module "kmem".
  306. */
  307. static void kmem_cache_alloc_verify(struct kmem_cache *cache, void *buf,
  308. int construct);
  309. /*
  310. * Method "alloc" of object type "cache" of module "kmem".
  311. */
  312. void *
  313. kmem_cache_alloc(struct kmem_cache *cache)
  314. {
  315. struct kmem_cpu_pool *cpu_pool;
  316. int filled, verify;
  317. void *buf;
  318. /* ... */;
  319. }
  320. /*
  321. * Function "info" of module "kmem".
  322. */
  323. void kmem_info(void);
  324. --------------------------------------------------------------------------------
  325. FUNCTIONS
  326. ---------
  327. Functions should do one thing, and do it well. Their name should be
  328. carefully chosen to best reflect their operation. Ideally, functions
  329. should be short enough to fit in a "page", i.e. not much more than
  330. 25 lines. The real metric developers should use to decide whether to
  331. break a function or not is the number of variables, including parameters.
  332. Assuming most people can remember around 5 things at the same time, you
  333. should break functions when the number of variables gets higher than
  334. this value. Variables such as a buffer pointer and its size can be
  335. considered a single variable.
  336. Do not hesitate to break functions down when things get even slightly
  337. complicated. If that helps, remember that static functions can easily
  338. be inlined by the compiler. See <<inline_functions,inline functions>>.
  339. Always name arguments in function prototypes.
  340. Common call protocols
  341. ~~~~~~~~~~~~~~~~~~~~~
  342. Functions should match one of the following call protocols :
  343. type get_value(...)::
  344. Accessor with no side effect.
  345. void do_something(...)::
  346. Function that cannot fail.
  347. struct my_struct * my_struct_lookup(...)::
  348. Function that returns an object, or NULL if an error occurred.
  349. int do_something(...)::
  350. Function that returns an error code, unless stated otherwise.
  351. It's easy to know when to return an object, or an error and the
  352. object through a pointer argument : if there is a single possible
  353. error code, let a NULL value encode that error, otherwise return
  354. it explicitely :
  355. struct my_struct * my_struct_create(...)::
  356. Return NULL if an error occurs, which may only be ENOMEM.
  357. int my_struct_create(struct my_struct **my_structp, ...)::
  358. Return an error (ENOMEM or something else) if creation fails, otherwise
  359. pass the new object to the caller through the double pointer argument
  360. and return 0.
  361. Methods, which are functions invoked on an object instance, must be
  362. defined so that their first argument is always the object instance
  363. on which the method is invoked.
  364. Unconditional branch statements
  365. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  366. Developers are encouraged to use unconditional branches in cases where
  367. they contribute to maintaining complexity low. Such cases include return
  368. on invalid argument, breaking or continuing simple loops, and centralized
  369. error handling. Note that this includes the *goto* statement. The rationale,
  370. beyond making error handling code common, is to keep the indentation level
  371. low. The main code flow, with the lowest indentation level, should match
  372. the most likely case. The compiler often uses heuristics based on keywords
  373. such as *return* or *goto* which are applied to the conditions of the
  374. containing block. You may also use the *likely* and *unlikely* macros
  375. to give hints about branches to the compiler in performance critical
  376. paths.
  377. Here is an example for object creation :
  378. [source,c]
  379. --------------------------------------------------------------------------------
  380. static int
  381. obj_create(struct obj **objp, int var)
  382. {
  383. struct subobj *subobj;
  384. struct obj *obj;
  385. int error;
  386. obj = kmem_cache_alloc(&obj_cache);
  387. if (obj == NULL) {
  388. return ENOMEM;
  389. }
  390. error = subobj_create(&subobj);
  391. if (error) {
  392. goto error_subobj;
  393. }
  394. error = obj_check_var(var);
  395. if (error) {
  396. goto error_var;
  397. }
  398. obj_init(obj, subobj, var);
  399. *objp = obj;
  400. return 0;
  401. error_var:
  402. subobj_destroy(subobj);
  403. error_subobj:
  404. kmem_cache_free(&obj_cache, obj);
  405. return error;
  406. }
  407. --------------------------------------------------------------------------------
  408. Local variables
  409. ~~~~~~~~~~~~~~~
  410. Local variables must be declared at the beginning of their scope. An empty
  411. line separates them from the function body. A notable exception is iterators,
  412. which may be declared inside loop statements.
  413. Common functions and methods
  414. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  415. The following list can be used to easily find appropriate standard names
  416. for the most common operations.
  417. *bootstrap*::
  418. This function is used for early module initialization. It should only
  419. exist if initialization must be broken down into multiple steps. If
  420. there is a single initialization step, run it in the *setup* function.
  421. *setup*::
  422. This function is used for module initialization.
  423. *init*::
  424. Object initialization that may not fail (e.g. without memory allocation).
  425. *build*::
  426. Object construction, i.e. initialization that may fail.
  427. *cleanup*::
  428. Object clean-up, releasing internal resources but not the object itself.
  429. *create*::
  430. Object creation, including both allocation and construction.
  431. *destroy*::
  432. Object destruction, releasing all resources including the object itself.
  433. *ref*::
  434. Add a reference to an object.
  435. *unref*::
  436. Remove a reference from an object, destroying it if there are no more
  437. references.
  438. *acquire* or *lock*::
  439. Acquire exclusive access to an object.
  440. *release* or *unlock*::
  441. Release exclusive access to an object.
  442. *add*::
  443. Add an object to a container.
  444. *remove*::
  445. Remove an object from a container.
  446. *lookup*::
  447. Look up an object in a container.
  448. [[inline_functions]]
  449. Inline functions
  450. ~~~~~~~~~~~~~~~~
  451. Do not abuse the inline keyword. First of all, this keyword is only a
  452. hint for the compiler, with no guarantee that a function will actually
  453. be inlined in the generated code. In addition, decent compilers can
  454. already inline functions without the presence of the keyword. Private
  455. functions (declared static) are easily inlined because the compiler
  456. knows it doesn't need to produce an externally visible symbol. Besides,
  457. with link-time optimizations (LTO), public functions can also be inlined
  458. or even removed if unused. As a result, use inline for a few performance
  459. critical short functions only.
  460. Passing arrays as arguments
  461. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  462. The C language automatically converts arrays to pointers when passed as
  463. function arguments. As a result, declaring an argument as an array is
  464. misleading. In particular, it may give the impression that the sizeof
  465. operator may be used safely to get the size of the array, when it
  466. actually always returns the size of a pointer. Therefore, declaring
  467. arguments as arrays is strictly forbidden.
  468. GIT COMMITS
  469. -----------
  470. Commits should be atomic, which means a single commit should focus on
  471. one functional modification. The size of the diff doesn't matter.
  472. The log format complies with the standard Git format, i.e. the log
  473. must start with a single line describing the changes, followed by
  474. an empty line and more details if necessary. Since any commit may be
  475. sent as email, try to limit lines to around 70 characters, so that
  476. there is room for replies before reaching/exceeding 80 characters.
  477. In addition to the standard Git format, the first line should start
  478. with the logical path of a module, e.g. *kern/kmem* or *x86/pmap*
  479. for architecture-specific modules, when changes are local to one
  480. or a few modules, which should be the case most of the time. For
  481. example :
  482. --------------------------------------------------------------------------------
  483. kern/kmem: undefine KMEM_VERIFY
  484. That macro was left over during the slab allocator rework.
  485. --------------------------------------------------------------------------------
  486. The first line being a short description, usable as an email subject,
  487. there is no need for a final dot. This also keeps it slightly shorter.
  488. --------------------------------------------------------------------------------
  489. kern/{sleepq,turnstile}: handle spurious wakeups
  490. --------------------------------------------------------------------------------
  491. This format is based on brace expansion in the bash shell.
  492. MISCELLANEOUS
  493. -------------
  494. *typedef* usage
  495. ~~~~~~~~~~~~~~~
  496. Usage of the *typedef* keyword is generally avoided. It is used in tricky
  497. situations, such as architecture-specific integer types, function pointers,
  498. and truely opaque data (none of which exist at the time of this writing).
  499. This rule is driven by the need to know as much as possible the nature of
  500. the data being processed. Readers should quickly be able to know whether
  501. a variable is an integer or a structure (or a union, which can cause bad
  502. surprises), and of course if it's a pointer. This could be done with a
  503. naming scheme, but that would only add unnecessary rules.
  504. Developers are allowed to use *typedef* for function pointers because,
  505. unlike a structure, without *typedef* a function pointer type has no name.
  506. It is strongly advised to end the name of the type with the suffix _fn_t.
  507. *sizeof* usage
  508. ~~~~~~~~~~~~~~
  509. One of the pillars of robust C code is correct usage of the *sizeof*
  510. operator. The main rule here is to always use *sizeof* on variables,
  511. not types. In addition, when iterating on arrays, use the *ARRAY_SIZE*
  512. macro, which can be thought of as *sizeof* in terms of items rather
  513. than bytes (technically characters). It is important that sizes are
  514. directly related to the data being processed, instead of e.g. reusing
  515. the macro used to declare an array again in the iteration code.
  516. Boolean Coercion
  517. ~~~~~~~~~~~~~~~~
  518. Boolean coercion should only be used when the resulting text is semantically
  519. valid, i.e. it can be understood that the expression is either true or false.
  520. For example :
  521. [source,c]
  522. --------------------------------------------------------------------------------
  523. int error;
  524. error = do_something();
  525. /* Valid */
  526. if (error) {
  527. if (error != EAGAIN) {
  528. printf("unexpected error\n");
  529. }
  530. return error;
  531. }
  532. int color;
  533. color = get_color();
  534. /* Invalid */
  535. if (!color) {
  536. print_black();
  537. } else if (color == 1) {
  538. print_red();
  539. }
  540. --------------------------------------------------------------------------------
  541. There are historical uses of the *int* type for boolean values, but all of
  542. them should be converted to the C99 *bool* type.
  543. Side effects and conditions
  544. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  545. Conditions must never be made of expressions with side effects. This
  546. completely removes the need to think about short-circuit evaluations.
  547. Increment/decrement operators
  548. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  549. Increment and decrement operators may never be used inside larger expressions.
  550. Their usage as expression-3 of a for loop is considered as an entire expression
  551. and doesn't violate this rule. The rationale is to avoid tricky errors related
  552. to sequence points. Since such operators may not be used inside larger
  553. expressions, there is no difference between prefix and postfix operators.
  554. The latter are preferred because they look more object-oriented, somewhat
  555. matching the object.method() syntax.
  556. Function-like macros with local variables
  557. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  558. Variable shadowing occurs in function-like macros if one of their local
  559. variables has the same name as one of the arguments. To avoid such situations,
  560. local variables in function-like macros must be named with an underscore
  561. suffix. This naming scheme is reserved for function-like macro variables.
  562. SEE
  563. ---
  564. manpage:intro
  565. {x15-operating-system}
  566. {the-art-of-unix-programming}