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
?
All of these disadvantage only effect the developer. What are the runtime disadvantages?
Did you really mean #include
everything? That would give you only a single module and let the optimizer see the entire program at once.
Actually, Microsoft's Visual C++ does exactly this when you use the /GL
(Whole Program Optimization) switch, it doesn't actually compile anything until the linker runs and has access to all code. Other compilers have similar options.