131f951b3SPatrick Williams# C++ Coding Style and Conventions
231f951b3SPatrick Williams
331f951b3SPatrick Williams## General Philosophy
431f951b3SPatrick Williams
531f951b3SPatrick WilliamsBeing an extensive and complicated language, there are often differences of
6f4febd00SPatrick Williamsopinions on "good" and "bad" C++ code. Bjarne Stroustrup has said "Within C++ is
7f4febd00SPatrick Williamsa smaller, simpler, safer language struggling to get out." We are striving to
8f4febd00SPatrick Williamswrite in this variant of C++ and are therefore following the "C++ Core
931f951b3SPatrick WilliamsGuidelines" that Bjarne and Herb Sutter introduced at CppCon 2015.
1031f951b3SPatrick Williams
1131f951b3SPatrick WilliamsBeyond a set of rules that help codify "good" and "bad" C++, we have general
1231f951b3SPatrick Williamsprinciples that help us align the software we develop with the constraints
1331f951b3SPatrick Williamswithin the problem domain being solved by OpenBMC. These are:
14f4febd00SPatrick Williams
1531f951b3SPatrick Williams1.  Code should be clear and concise.
1631f951b3SPatrick Williams2.  Code should be written with modern practices.
1731f951b3SPatrick Williams3.  Code should be performant.
1831f951b3SPatrick Williams
1931f951b3SPatrick Williams### Code should be clear and concise
2031f951b3SPatrick Williams
2131f951b3SPatrick Williams> Brevity is the soul of wit.
2231f951b3SPatrick Williams
2331f951b3SPatrick WilliamsIt is important that code be optimized for the reviewer and maintainer and not
24f4febd00SPatrick Williamsfor the writer. Solutions should avoid tricks that detract from the clarity of
25f4febd00SPatrick Williamsreviewing and understanding it.
2631f951b3SPatrick Williams
2731f951b3SPatrick WilliamsModern practices allow C++ to be an expressive, but concise, language. We tend
2831f951b3SPatrick Williamsto favor solutions which succinctly represent the problem in as few lines as
2931f951b3SPatrick Williamspossible.
3031f951b3SPatrick Williams
3131f951b3SPatrick WilliamsWhen there is a conflict between clarity and conciseness, clarity should win
3231f951b3SPatrick Williamsout.
3331f951b3SPatrick Williams
3431f951b3SPatrick Williams### Code should be written with modern practices
3531f951b3SPatrick Williams
3631f951b3SPatrick WilliamsWe strive to keep our code conforming to and utilizing of the latest in C++
37*0666ef8aSPatrick Williamsstandards. Today, that means all C++ code should be compiled using C++23
38*0666ef8aSPatrick Williamscompiler settings. As the C++26 standard is finalized and compilers support it,
39f4febd00SPatrick Williamswe will move to it as well.
4031f951b3SPatrick Williams
4131f951b3SPatrick WilliamsWe also strive to keep the codebase up-to-date with the latest recommended
4231f951b3SPatrick Williamspractices by the language designers. This is reflected by the choice in
4331f951b3SPatrick Williamsfollowing the C++ Core Guidelines.
4431f951b3SPatrick Williams
45b86de0f1SPatrick WilliamsWe finally desire to have computers do our thinking for us wherever possible.
46b86de0f1SPatrick WilliamsThis means having Continuous Integration tests on each repository so that
47f4febd00SPatrick Williamsregressions are quickly identified prior to merge. It also means having as much
48f4febd00SPatrick Williamsof this document enforced by tools as possible by, for example, clang-format and
49f4febd00SPatrick Williamsclang-tidy.
5031f951b3SPatrick Williams
5131f951b3SPatrick WilliamsFor those coming to the project from pre-C++11 environments we strongly
5231f951b3SPatrick Williamsrecommend the book "Effective Modern C++" as a way to get up to speed on the
53200e9db1SJosh Lehandifferences between C++98/03 and C++11/14/17/20.
5431f951b3SPatrick Williams
5531f951b3SPatrick Williams### Code should be performant.
5631f951b3SPatrick Williams
5731f951b3SPatrick WilliamsOpenBMC targets embedded processors that typically have 32-64MB of flash and
58f4febd00SPatrick Williamssimilar processing power of a typical smart-watch available in 2016. This means
59f4febd00SPatrick Williamsthat there are times where we must limit library selection and/or coding
6031f951b3SPatrick Williamstechniques to compensate for this constraint. Due to the current technology,
6131f951b3SPatrick Williamsperformance evaluation is done in order of { code size, cpu utilization, and
6231f951b3SPatrick Williamsmemory size }.
6331f951b3SPatrick Williams
6431f951b3SPatrick WilliamsFrom a macro-optimization perspective, we expect all solutions to have an
6531f951b3SPatrick Williamsappropriate algorithmic complexity for the problem at hand. Therefore, an
6631f951b3SPatrick Williams`O(n^3)` algorithm may be rejected even though it has good clarity when an
6731f951b3SPatrick Williams`O(n*lg(n))` solution exists.
6831f951b3SPatrick Williams
6931f951b3SPatrick Williams## Global Guidelines and Practices
7031f951b3SPatrick Williams
7131f951b3SPatrick WilliamsPlease follow the guidelines established by the C++ Core Guidelines (CCG).
7231f951b3SPatrick Williams
7331f951b3SPatrick Williamshttps://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md
7431f951b3SPatrick Williams
7531f951b3SPatrick Williams[[Last reviewed revision is 53bc78f]]
7631f951b3SPatrick Williams
7731f951b3SPatrick WilliamsExceptions:
7831f951b3SPatrick Williams
7931f951b3SPatrick Williams### Guideline Support Library (GSL)
8031f951b3SPatrick Williams
8131f951b3SPatrick WilliamsWe do not currently utilize the Guideline Support Library provided by the CCG.
8231f951b3SPatrick WilliamsAny recommendation within the CCG of GSL conventions may be ignored at this
8331f951b3SPatrick Williamstime.
8431f951b3SPatrick Williams
8531f951b3SPatrick Williams### Style recommendations
8631f951b3SPatrick Williams
8731f951b3SPatrick WilliamsThe following are not followed:
88f4febd00SPatrick Williams
89f4febd00SPatrick Williams- NL.10 Avoid CamelCase
90f4febd00SPatrick Williams- NL.17 Use K&R-derived layout
9131f951b3SPatrick Williams
9231f951b3SPatrick Williams## Library and Feature Specifics
9331f951b3SPatrick Williams
9431f951b3SPatrick WilliamsAdditional recommendations within the OpenBMC project on specific language
9531f951b3SPatrick Williamsfeatures or libraries.
9631f951b3SPatrick Williams
9731f951b3SPatrick Williams### Exceptions
9831f951b3SPatrick Williams
9931f951b3SPatrick WilliamsWe do use exceptions as a basis for error handling within OpenBMC.
10031f951b3SPatrick Williams
10156d79455SEd Tanous### Boost
10231f951b3SPatrick Williams
10356d79455SEd TanousUse of boost is allowed, under the following circumstances:
104f4febd00SPatrick Williams
10556d79455SEd Tanous1. Use is done as a header-only library. This allows unused functions and
10656d79455SEd Tanous   methods to be removed by the compiler at link time, and avoids adding large
10756d79455SEd Tanous   amounts of overhead and flash usage.
10856d79455SEd Tanous2. Implementers should include the lowest level header required to solve the
10956d79455SEd Tanous   problem at hand. This allows uses to be found and moved forward when new
11056d79455SEd Tanous   standards are available, as well as reduce compile times, and decrease the
11156d79455SEd Tanous   possibility of accidental use. (ie, #include <boost/container/flat_map.hpp>
11256d79455SEd Tanous   not #include <boost/container.hpp>)
11356d79455SEd Tanous3. The module used should not have an equivalent in the std namespace that meets
114f4febd00SPatrick Williams   the same requirements for implementation or clarity: For example, std::chrono
115f4febd00SPatrick Williams   should be preferred over boost::chrono. std::array over boost::array.
11656d79455SEd Tanous4. Use does not conflict with any of the core tenants of this coding standard
11756d79455SEd Tanous   (clarity, modern practices, or performance).
11831f951b3SPatrick Williams
11931f951b3SPatrick Williams### iostream
12031f951b3SPatrick Williams
12131f951b3SPatrick WilliamsThe iostream conventions of using 'operator<<' contribute to an increased code
12231f951b3SPatrick Williamssize over printf-style operations, due to individual function calls for each
123f4febd00SPatrick Williamsappended value. We therefore do not use iostreams, or iostream-style APIs, for
124f4febd00SPatrick Williamslogging.
12531f951b3SPatrick Williams
12631f951b3SPatrick WilliamsThere are cases when using an iostream utility (such as sstream) can result in
12731f951b3SPatrick Williamsclearer and similar-sized code. iostream may be used in those situations.
12831f951b3SPatrick Williams
12931f951b3SPatrick Williams## Coding Style
13031f951b3SPatrick Williams
13131f951b3SPatrick WilliamsIndentation, naming practices, etc.
13231f951b3SPatrick Williams
13331f951b3SPatrick Williams### General
13431f951b3SPatrick Williams
135f4febd00SPatrick Williams- Line length should be limited to 80 characters.
136f4febd00SPatrick Williams- Indentation should be done with 4 space characters.
137f4febd00SPatrick Williams- Files should use Unix-style newlines (\n).
13831f951b3SPatrick Williams
13976d8f7f7SAndrew Geissler### Clang Formatting
14076d8f7f7SAndrew Geissler
141f4febd00SPatrick WilliamsIndividual OpenBMC repositories can use
142f4febd00SPatrick Williams[clang-format](https://clang.llvm.org/docs/ClangFormat.html) if desired. The
143f4febd00SPatrick WilliamsOpenBMC CI infrastructure will automatically verify the code formatting on code
144f4febd00SPatrick Williamscheck-in if a .clang_format file is found within the root directory of the
145f4febd00SPatrick Williamsrepository. This allows for automatic validation of code formatting upon
146f4febd00SPatrick Williamscheck-in.
14776d8f7f7SAndrew Geissler
148f62262b3SAdriana KobylakIf a custom configuration is desired, such as using different clang formatting
149f62262b3SAdriana Kobylakfor C and C++ files, a format-code.sh script can be created, which can for
150f4febd00SPatrick Williamsexample use different .clang\* files as input depending on the file type. The
151f4febd00SPatrick Williamsformat-code.sh script will be executed as part of CI if found in the root
152f62262b3SAdriana Kobylakdirectory of the repository, and will check that there are no files that were
153f62262b3SAdriana Kobylakmodified after running it (same check as running clang).
154f62262b3SAdriana Kobylak
155f4febd00SPatrick WilliamsOpenBMC requires a clang-format of version 6.0 or greater. An example of how to
156f4febd00SPatrick Williamsrun clang-format against all code in your repo can be found by referencing the
157f4febd00SPatrick Williams[tool](https://github.com/openbmc/openbmc-build-scripts/blob/master/scripts/format-code.sh)
158f4febd00SPatrick Williamsused by CI.
15976d8f7f7SAndrew Geissler
1600dcc430aSPatrick Venture[Example .clang-format](https://www.github.com/openbmc/docs/blob/master/style/cpp/.clang-format)
16176d8f7f7SAndrew Geissler
16231f951b3SPatrick Williams### Bracket style
16331f951b3SPatrick Williams
164f4febd00SPatrick Williams- Utilize 'Allman' style brackets. Brackets are on their own line at the same
16531f951b3SPatrick Williams  indentation level as the statement that creates the scope.
16631f951b3SPatrick Williams
16731f951b3SPatrick Williams```
16831f951b3SPatrick Williamsif (condition)
16931f951b3SPatrick Williams{
17031f951b3SPatrick Williams    ...
17131f951b3SPatrick Williams}
17231f951b3SPatrick Williams```
17331f951b3SPatrick Williams
17431f951b3SPatrick Williams```
17531f951b3SPatrick Williamsvoid foo()
17631f951b3SPatrick Williams{
17731f951b3SPatrick Williams    ...
17831f951b3SPatrick Williams}
17931f951b3SPatrick Williams```
18031f951b3SPatrick Williams
181f4febd00SPatrick Williams- Even one line conditional and loop statements should have brackets.
18231f951b3SPatrick Williams
18331f951b3SPatrick Williams```
18431f951b3SPatrick Williams/// Wrong.
18531f951b3SPatrick Williamsif (condition)
18631f951b3SPatrick Williams    do_something;
18731f951b3SPatrick Williams
18831f951b3SPatrick Williams/// Correct
18931f951b3SPatrick Williamsif (condition)
19031f951b3SPatrick Williams{
19131f951b3SPatrick Williams    do_something;
19231f951b3SPatrick Williams}
19331f951b3SPatrick Williams```
19431f951b3SPatrick Williams
19531f951b3SPatrick Williams### Indentation
19631f951b3SPatrick Williams
197f4febd00SPatrick Williams- Content within a namespace should be at the same indentation level as the
19831f951b3SPatrick Williams  namespace itself.
19931f951b3SPatrick Williams
20031f951b3SPatrick Williams```
20131f951b3SPatrick Williamsnamespace foo
20231f951b3SPatrick Williams{
20331f951b3SPatrick Williams
20431f951b3SPatrick Williamscontent
20531f951b3SPatrick Williams
20631f951b3SPatrick Williams}
20731f951b3SPatrick Williams```
20831f951b3SPatrick Williams
209f4febd00SPatrick Williams- Content within a class / struct should be indented.
21031f951b3SPatrick Williams
21131f951b3SPatrick Williams```
21231f951b3SPatrick Williamsclass Foo
21331f951b3SPatrick Williams{
21431f951b3SPatrick Williams    public:
21531f951b3SPatrick Williams        Foo();
21631f951b3SPatrick Williams}
21731f951b3SPatrick Williams```
21831f951b3SPatrick Williams
219f4febd00SPatrick Williams- Content within a function / conditional / loop should be indented.
22031f951b3SPatrick Williams
22131f951b3SPatrick Williams```
22231f951b3SPatrick Williamsvoid foo()
22331f951b3SPatrick Williams{
22431f951b3SPatrick Williams    while (1)
22531f951b3SPatrick Williams    {
22631f951b3SPatrick Williams        if (bar())
22731f951b3SPatrick Williams        {
22831f951b3SPatrick Williams            ...
22931f951b3SPatrick Williams        }
23031f951b3SPatrick Williams    }
23131f951b3SPatrick Williams}
23231f951b3SPatrick Williams```
23331f951b3SPatrick Williams
234f4febd00SPatrick Williams- Switch / case statements should be indented.
23531f951b3SPatrick Williams
23631f951b3SPatrick Williams```
23731f951b3SPatrick Williamsswitch (foo)
23831f951b3SPatrick Williams{
23931f951b3SPatrick Williams    case bar:
24031f951b3SPatrick Williams    {
24131f951b3SPatrick Williams        bar();
24231f951b3SPatrick Williams        break;
24331f951b3SPatrick Williams    }
24431f951b3SPatrick Williams
24531f951b3SPatrick Williams    case baz:
24631f951b3SPatrick Williams    {
24731f951b3SPatrick Williams        baz();
24831f951b3SPatrick Williams        break;
24931f951b3SPatrick Williams    }
25031f951b3SPatrick Williams}
25131f951b3SPatrick Williams```
25231f951b3SPatrick Williams
253f4febd00SPatrick Williams- Labels should be indented so they appear at 1 level less than the current
254f4febd00SPatrick Williams  indentation, rather than flush to the left. (This is not to say that goto and
255f4febd00SPatrick Williams  labels are preferred or should be regularly used, but simply when they are
256f4febd00SPatrick Williams  used, this is how they are to be used.)
25731f951b3SPatrick Williams
25831f951b3SPatrick Williams```
25931f951b3SPatrick Williamsvoid foo()
26031f951b3SPatrick Williams{
26131f951b3SPatrick Williams    if (bar)
26231f951b3SPatrick Williams    {
26331f951b3SPatrick Williams        do
26431f951b3SPatrick Williams        {
26531f951b3SPatrick Williams            if (baz)
26631f951b3SPatrick Williams            {
26731f951b3SPatrick Williams                goto exit;
26831f951b3SPatrick Williams            }
26931f951b3SPatrick Williams
27031f951b3SPatrick Williams        } while(1);
27131f951b3SPatrick Williams
27231f951b3SPatrick Williams    exit:
27331f951b3SPatrick Williams        cleanup();
27431f951b3SPatrick Williams    }
27531f951b3SPatrick Williams}
27631f951b3SPatrick Williams```
27731f951b3SPatrick Williams
27831f951b3SPatrick Williams### Naming Conventions.
27931f951b3SPatrick Williams
280f4febd00SPatrick Williams- We generally abstain from any prefix or suffix on names.
281f4febd00SPatrick Williams- Acronyms should be same-case throughout and follow the requirements as in
282f4febd00SPatrick Williams  their appropriate section.
28345da6196SPatrick Williams
28445da6196SPatrick Williams```
28545da6196SPatrick Williams/// Correct.
28645da6196SPatrick WilliamsSomeBMCType someBMCVariable = bmcFunction();
28745da6196SPatrick Williams
28845da6196SPatrick Williams/// Wrong: type and variable are mixed-case, function isn't lowerCamelCase.
28945da6196SPatrick WilliamsSomeBmcType someBmcVariable = BMCFunction();
29045da6196SPatrick Williams```
29131f951b3SPatrick Williams
2929f34110aSPatrick Venture### Header Ordering
2939f34110aSPatrick Venture
2949f34110aSPatrick VentureHeader inclusion order for a header file:
295f4febd00SPatrick Williams
2969f34110aSPatrick Venture```
2979f34110aSPatrick Venturelocal headers (e.g. "daemon_sys.hpp")
2989f34110aSPatrick Venturec-libraries
2999f34110aSPatrick Venturecpp-libraries (including openbmc libraries)
3009f34110aSPatrick Venture```
3019f34110aSPatrick Venture
3029f34110aSPatrick VentureHeader inclusion order for a source file:
303f4febd00SPatrick Williams
3049f34110aSPatrick Venture```
3059f34110aSPatrick Venturesource.hpp (if applicable)
3069f34110aSPatrick Venturelocal headers
3079f34110aSPatrick Venturec-libraries
3089f34110aSPatrick Venturecpp-libraries
3099f34110aSPatrick Venture```
3109f34110aSPatrick Venture
3119f34110aSPatrick VentureAll in alphabetically sorted order.
3129f34110aSPatrick Venture
31331f951b3SPatrick Williams#### Files
31431f951b3SPatrick Williams
315f4febd00SPatrick Williams- C++ headers should end in ".hpp". C headers should end in ".h".
316f4febd00SPatrick Williams- C++ files should be named with lower_snake_case.
31731f951b3SPatrick Williams
31831f951b3SPatrick Williams#### Types
31931f951b3SPatrick Williams
320f4febd00SPatrick Williams- Prefer 'using' over 'typedef' for type aliases.
321f4febd00SPatrick Williams- Structs, classes, enums, and typed template parameters should all be in
32231f951b3SPatrick Williams  UpperCamelCase.
323f4febd00SPatrick Williams- Prefer namespace scoping rather than long names with prefixes.
324f4febd00SPatrick Williams- A single-word type alias within a struct / class may be lowercase to match STL
325f4febd00SPatrick Williams  conventions (`using type = T`) while a multi-word type alias should be
32631f951b3SPatrick Williams  UpperCamelCase (`using ArrayOfT = std::array<T, N>`).
327f4febd00SPatrick Williams- Exception: A library API may use lower_snake_case to match conventions of the
328f4febd00SPatrick Williams  STL or an underlying C library it is abstracting. Application APIs should all
329f4febd00SPatrick Williams  be UpperCamelCase.
330f4febd00SPatrick Williams- Exception: A for-convenience template type alias of a template class may end
33131f951b3SPatrick Williams  in `_t` to match the conventions of the STL.
33231f951b3SPatrick Williams
33331f951b3SPatrick Williams```
33431f951b3SPatrick Williamstemplate <typename T>
33584ef2aa2SPatrick Ventureclass Foo
33631f951b3SPatrick Williams{
33731f951b3SPatrick Williams    using type = std::decay_t<T>;
33831f951b3SPatrick Williams};
33931f951b3SPatrick Williams
34084ef2aa2SPatrick Venturetemplate <typename T> using foo_t = Foo<T>::type;
34131f951b3SPatrick Williams```
34231f951b3SPatrick Williams
34331f951b3SPatrick Williams#### Variables
34431f951b3SPatrick Williams
345f4febd00SPatrick Williams- Variables should all be lowerCamelCase, including class members, with no
34631f951b3SPatrick Williams  underscores.
34731f951b3SPatrick Williams
34831f951b3SPatrick Williams#### Functions
34931f951b3SPatrick Williams
350f4febd00SPatrick Williams- Functions should all be lowerCamelCase.
351f4febd00SPatrick Williams- Exception: A library API may use lower_snake-case to match conventions of the
352f4febd00SPatrick Williams  STL or an underlying C library it is abstracting. Application APIs should all
353f4febd00SPatrick Williams  be lowerCamelCase.
35431f951b3SPatrick Williams
35531f951b3SPatrick Williams#### Constants
35631f951b3SPatrick Williams
357f4febd00SPatrick Williams- Constants and enum members should be named like variables in lowerCamelCase.
35831f951b3SPatrick Williams
35931f951b3SPatrick Williams#### Namespaces
36031f951b3SPatrick Williams
361f4febd00SPatrick Williams- Namespaces should be lower_snake_case.
362f4febd00SPatrick Williams- Top-level namespace should be named based on the containing repository.
363f4febd00SPatrick Williams- Favor a namespace called 'details' or 'internal' to indicate the equivalent of
364f4febd00SPatrick Williams  a "private" namespace in a header file and anonymous namespaces in a C++ file.
36531f951b3SPatrick Williams
36631f951b3SPatrick Williams### Header Guards
36731f951b3SPatrick Williams
36831f951b3SPatrick WilliamsPrefer '#pragma once' header guard over '#ifndef'-style.
36931f951b3SPatrick Williams
37031f951b3SPatrick Williams### Additional Whitespace
37131f951b3SPatrick Williams
372f4febd00SPatrick Williams- Follow NL.18: Use C++-style declarator layout.
37331f951b3SPatrick Williams
37431f951b3SPatrick Williams```
37531f951b3SPatrick Williamsfoo(T& bar, const S* baz); /// Correct.
37631f951b3SPatrick Williamsfoo(T &bar, const S *baz); /// Incorrect.
37731f951b3SPatrick Williams```
37831f951b3SPatrick Williams
379f4febd00SPatrick Williams- Follow NL.15: Use spaces sparingly.
38031f951b3SPatrick Williams
381f4febd00SPatrick Williams- Insert whitespace after a conditional and before parens.
38231f951b3SPatrick Williams
38331f951b3SPatrick Williams```
38431f951b3SPatrick Williamsif (...)
38531f951b3SPatrick Williamswhile (...)
38631f951b3SPatrick Williamsfor (...)
38731f951b3SPatrick Williams```
38831f951b3SPatrick Williams
389f4febd00SPatrick Williams- Insert whitespace around binary operators for readability.
39031f951b3SPatrick Williams
39131f951b3SPatrick Williams```
39231f951b3SPatrick Williamsfoo((a-1)/b,c-2); /// Incorrect.
39331f951b3SPatrick Williamsfoo((a - 1) / b, c - 2); /// Correct.
39431f951b3SPatrick Williams```
39531f951b3SPatrick Williams
396f4febd00SPatrick Williams- Do not insert whitespace around unary operators.
397f4febd00SPatrick Williams
39831f951b3SPatrick Williams```
39931f951b3SPatrick Williamsa = * b;  /// Incorrect.
40031f951b3SPatrick Williamsa = & b;  /// Incorrect.
40131f951b3SPatrick Williamsa = b -> c;  /// Incorrect.
40231f951b3SPatrick Williamsif (! a)  /// Incorrect.
40331f951b3SPatrick Williams```
40431f951b3SPatrick Williams
405f4febd00SPatrick Williams- Do not insert whitespace inside parens or between a function call and
40631f951b3SPatrick Williams  parameters.
40731f951b3SPatrick Williams
40831f951b3SPatrick Williams```
40931f951b3SPatrick Williamsfoo(x, y); /// Correct.
41031f951b3SPatrick Williamsfoo ( x , y ); /// Incorrect.
41131f951b3SPatrick Williams
41231f951b3SPatrick Williamsdo (...)
41331f951b3SPatrick Williams{
41431f951b3SPatrick Williams} while(0); /// 'while' here is structured like a function call.
41531f951b3SPatrick Williams```
41631f951b3SPatrick Williams
417f4febd00SPatrick Williams- Prefer line-breaks after operators to show continuation.
418f4febd00SPatrick Williams
41931f951b3SPatrick Williams```
42031f951b3SPatrick Williamsif (this1 == that1 &&
42131f951b3SPatrick Williams    this2 == that2) /// Correct.
42231f951b3SPatrick Williams
42331f951b3SPatrick Williamsif (this1 == that1
42431f951b3SPatrick Williams    && this2 == that2) /// Incorrect.
42531f951b3SPatrick Williams```
42631f951b3SPatrick Williams
427f4febd00SPatrick Williams- Long lines should have continuation start at the same level as the parens or
42831f951b3SPatrick Williams  all all items inside the parens should be at a 2-level indent.
42931f951b3SPatrick Williams
43031f951b3SPatrick Williams```
43131f951b3SPatrick WilliamsreallyLongFunctionCall(foo,
43231f951b3SPatrick Williams                       bar,
43331f951b3SPatrick Williams                       baz); // Correct.
43431f951b3SPatrick Williams
43531f951b3SPatrick WilliamsreallyLongFunctionCall(
43631f951b3SPatrick Williams        foo,
43731f951b3SPatrick Williams        bar,
43831f951b3SPatrick Williams        baz); // Also correct.
43931f951b3SPatrick Williams
44031f951b3SPatrick WilliamsreallyLongFunctionCall(
44131f951b3SPatrick Williams        foo, bar, baz); // Similarly correct.
44231f951b3SPatrick Williams
44331f951b3SPatrick WilliamsreallyLongFunctionCall(foo,
44431f951b3SPatrick Williams        bar,
44531f951b3SPatrick Williams        baz); // Incorrect.
44631f951b3SPatrick Williams```
44731f951b3SPatrick Williams
44831f951b3SPatrick Williams### Misc Guidelines.
44931f951b3SPatrick Williams
450f4febd00SPatrick Williams- Always use `size_t` or `ssize_t` for things that are sizes, counts, etc. You
451f4febd00SPatrick Williams  need a strong rationale for using a sized type (ex. `uint8_t`) when a size_t
452f4febd00SPatrick Williams  will do.
45331f951b3SPatrick Williams
454f4febd00SPatrick Williams- Use `uint8_t`, `int16_t`, `uint32_t`, `int64_t`, etc. for types where size is
455b4cf1288SZev Weiss  important due to interactions with hardware or some externally defined API/ABI
456b4cf1288SZev Weiss  (such as a system call or library interface). Do not use them, without good
457b4cf1288SZev Weiss  reason, when such interaction is not involved; prefer size_t or int instead.
458