blob: 3fa640c8f8bfcb518d46d504ac11e92d5fac168d [file] [log] [blame] [view]
Artem Titova6178672023-01-30 10:51:011<!-- go/cmark -->
Danil Chapovalov787b9072024-09-02 11:48:332<!--* freshness: {owner: 'danilchap' reviewed: '2024-09-02'} *-->
Artem Titova6178672023-01-30 10:51:013
Karl Wiberg08c5cb02018-03-14 11:23:124# `.h` and `.cc` files come in pairs
5
Artem Titova6178672023-01-30 10:51:016This is an overflow page for [this](/g3doc/style-guide.md#h-cc-pairs)
Karl Wiberg08c5cb02018-03-14 11:23:127style rule.
8
9## Example violations
10
11Example violations, which should be avoided in new code:
12
13* Declarations in `path/to/include/foo.h`, definitions in
14 `path/to/source/foo.cc`. **Fix:** The `.h` and `.cc` files should be
15 in the same directory.
16* Declarations in `foo.h`, definitions in both `foo_bar.cc` and
17 `foo_baz.cc`. **Fix:** The `.h` and `.cc` files should come in
18 pairs, so either split `foo.h` into `foo_bar.h` and `foo_baz.h`, or
19 merge `foo_bar.cc` and `foo_baz.cc` into `foo.cc`.
20
21## Exception for platform-specific code
22
23If the functions in a header file need different implementations for
24different platforms, we allow the following arrangement:
25
26* Declarations in `foo.h`.
27* A complete set of matching definitions in `foo_win.cc`, another
28 complete set of matching definitions in `foo_mac.cc`, and so on.
29* As per the main rule, these files should all be in the same
30 directory and in the same build target. The build target should use
31 platform conditionals to ensure that exactly one of the `.cc` files
32 are included.