Quote:Original post by Kylotan
What I said may have been misleading. In general C++ compilers are not required to make multiple passes over the source; after all, if they did, many things that the language requires would not be necessary. But of course they may do so, in order to improve your code, but all your declarations have to make sense as if they are being compiled in one pass. At some point, it does have to start generating code, and it's not always practical or even possible to determine a perfect order to do this that won't miss any chances at optimisation. (Though this is not such an example.) So ideally you want the compiler to know that the function is inline before it ever attempts to use it. Compilers do a lot of great stuff but occasionally they miss a simple trick.
What? A compiler will have a perfect view of the call graph, or else it wouldn't be able to compile much of anything. Therefore, it will have a complete view of what functions have been hinted at inline and which haven't.
As others have pointed out, the compiler is free to ignore the keyword (just like the "register" keyword), but that's not a result of the compiler having an incomplete view of that aspect of the source.
On a somewhat related note, "Link Time Code Generation" lets the compiler do optimizations across modules, by doing compilation on a merged code tree.
And, while on the subject, people should
not assume that inlining code will always make things faster. Inlining increases the likelyhood of blowing the instruction cache, sometimes with very negative results (there's a longer, rantier real-world example I gave about code size
here).