First off, I am not looking for a way to force the compiler to inline the implementation of every function.
To reduce the level of misguided answers make sure you understand what the inline
keyword actually means. Here is good description, inline vs static vs extern.
So my question, why not mark every function definition inline
? ie Ideally, the only compilation unit would be main.cpp
. Or possibly a few more for the functions that cannot be defined in a header file (pimpl idiom, etc).
The theory behind this odd request is it would give the optimizer maximum information to work with. It could inline function implementations of course, but it could also do "cross-module" optimization as there is only one module. Are there other advantages?
Has any one tried this in with a real application? Did the performance increase? decrease?!?
What are the disadvantages of marking all function definitions inline
?
- Compilation might be slower and will consume much more memory.
- Iterative builds are broken, the entire application will need to be rebuilt after every change.
- Link times might be astronomical
All of these disadvantage only effect the developer. What are the runtime disadvantages?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…