1*d9f75844SAndroid Build Coastguard Worker# `.h` and `.cc` files come in pairs 2*d9f75844SAndroid Build Coastguard Worker 3*d9f75844SAndroid Build Coastguard Worker<?% config.freshness.owner = 'danilchap' %?> 4*d9f75844SAndroid Build Coastguard Worker<?% config.freshness.reviewed = '2021-05-12' %?> 5*d9f75844SAndroid Build Coastguard Worker 6*d9f75844SAndroid Build Coastguard WorkerThis is an overflow page for [this](../style-guide.md#h-cc-pairs) 7*d9f75844SAndroid Build Coastguard Workerstyle rule. 8*d9f75844SAndroid Build Coastguard Worker 9*d9f75844SAndroid Build Coastguard Worker## Example violations 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard WorkerExample violations, which should be avoided in new code: 12*d9f75844SAndroid Build Coastguard Worker 13*d9f75844SAndroid Build Coastguard Worker* Declarations in `path/to/include/foo.h`, definitions in 14*d9f75844SAndroid Build Coastguard Worker `path/to/source/foo.cc`. **Fix:** The `.h` and `.cc` files should be 15*d9f75844SAndroid Build Coastguard Worker in the same directory. 16*d9f75844SAndroid Build Coastguard Worker* Declarations in `foo.h`, definitions in both `foo_bar.cc` and 17*d9f75844SAndroid Build Coastguard Worker `foo_baz.cc`. **Fix:** The `.h` and `.cc` files should come in 18*d9f75844SAndroid Build Coastguard Worker pairs, so either split `foo.h` into `foo_bar.h` and `foo_baz.h`, or 19*d9f75844SAndroid Build Coastguard Worker merge `foo_bar.cc` and `foo_baz.cc` into `foo.cc`. 20*d9f75844SAndroid Build Coastguard Worker 21*d9f75844SAndroid Build Coastguard Worker## Exception for platform-specific code 22*d9f75844SAndroid Build Coastguard Worker 23*d9f75844SAndroid Build Coastguard WorkerIf the functions in a header file need different implementations for 24*d9f75844SAndroid Build Coastguard Workerdifferent platforms, we allow the following arrangement: 25*d9f75844SAndroid Build Coastguard Worker 26*d9f75844SAndroid Build Coastguard Worker* Declarations in `foo.h`. 27*d9f75844SAndroid Build Coastguard Worker* A complete set of matching definitions in `foo_win.cc`, another 28*d9f75844SAndroid Build Coastguard Worker complete set of matching definitions in `foo_mac.cc`, and so on. 29*d9f75844SAndroid Build Coastguard Worker* As per the main rule, these files should all be in the same 30*d9f75844SAndroid Build Coastguard Worker directory and in the same build target. The build target should use 31*d9f75844SAndroid Build Coastguard Worker platform conditionals to ensure that exactly one of the `.cc` files 32*d9f75844SAndroid Build Coastguard Worker are included. 33