I always read that inlined functions should be short functions because otherwise the executable gets bloated with too many copies of the same code.
However, I try to refactor my code and write small helper functions, which are often not so small (20-30 lines) and often only used by exactly one other function, e.g. to avoid the do{...}while(false);
idiom.
Hence my questions:
- Wouldn't it be a good idea to inline a long function, if it is only used by exactly one other function regardless of how long it is? The size of the executable would be the same, and one function call would be saved.
- Would a good compiler consider this? Or is the length a strong criterion to not-inline a function. Does this depend on whether I explicitly write
inline
, as compilers seem to ignore this mostly?