xref: /aosp_15_r20/external/webrtc/g3doc/style-guide/h-cc-pairs.md (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1# `.h` and `.cc` files come in pairs
2
3<?% config.freshness.owner = 'danilchap' %?>
4<?% config.freshness.reviewed = '2021-05-12' %?>
5
6This is an overflow page for [this](../style-guide.md#h-cc-pairs)
7style 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.
33