• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# `.h` and `.cc` files come in pairs
2
3This is an overflow page for [this](../style-guide.md#h-cc-pairs)
4style rule.
5
6## Example violations
7
8Example violations, which should be avoided in new code:
9
10* Declarations in `path/to/include/foo.h`, definitions in
11  `path/to/source/foo.cc`. **Fix:** The `.h` and `.cc` files should be
12  in the same directory.
13* Declarations in `foo.h`, definitions in both `foo_bar.cc` and
14  `foo_baz.cc`. **Fix:** The `.h` and `.cc` files should come in
15  pairs, so either split `foo.h` into `foo_bar.h` and `foo_baz.h`, or
16  merge `foo_bar.cc` and `foo_baz.cc` into `foo.cc`.
17
18## Exception for platform-specific code
19
20If the functions in a header file need different implementations for
21different platforms, we allow the following arrangement:
22
23* Declarations in `foo.h`.
24* A complete set of matching definitions in `foo_win.cc`, another
25  complete set of matching definitions in `foo_mac.cc`, and so on.
26* As per the main rule, these files should all be in the same
27  directory and in the same build target. The build target should use
28  platform conditionals to ensure that exactly one of the `.cc` files
29  are included.
30