c - Should reliance on indirect header inclusion be used? -
if project has header includes second header , both of them include common header, practice drop inclusion of common header first header , rely on indirect inclusion via second header?
e.g.: know stdint.h can removed temperature.h, should be?
in temperature.h:
#include <stdint.h> // *should* include removed in case. #include "i2c.h" extern uint16_t temperatureread (i2cdata_t x); in i2c.h:
#include <stdint.h> typedef struct i2cdata_t { uint16_t examplemember } i2cdata_t;
generally want modules self contained. if module relies on in header include it. temperature.h may 1 day decide doesn't need include stdint.h more , have removed. code should has nothing decision, safeguard including stdint.h, i.e. self contained.
use header guards (or in ms c++ pragma once) make sure compilation speed doesn't degrade due including header multiple times.
Comments
Post a Comment