# Modern Compilers Inlining and Header and Implementation Practices in Game Development

I was taught that in general practice its best not to try to beat the compiler, at least until its proven to be stupid. So in general, and since I was told that its generally only used as a suggestion to the compiler, the inline tag has never been a priority for me to use because I was taught that the compiler is pretty good when it comes to understanding the trade offs your system will have to make when it comes to inlining vs. looped calls to a function pointer for example.

But then I just read that functions cannot be inlined unless they are defined in the header file because otherwise the compiler won't see it when it starts to work on other header and cpp files (read from . I did some more research and I found that some people were saying that this is the old way things worked and that modern compilers perform "Whole Program Optimization" or "Link-Time Code Generation" which is responsible for the construction of the obj files that I'm used to seeing which can then be linked together and optimized further such as allowing the compiler to see functions in the obj file that were once "hidden" in the cpp file and then inline optimize them where appropriate. This sounds great but I'm wondering which source to trust and was wondering if I could get an additional opinion on the matter.

On the other hand I was reading up on header only implementations and how they tend to be used in libraries to increase compiler optimizations and was wondering if its was also a standard practice in game development or if it was typical to separate declaration and implementation into different files when developing a game engine.

Thanks in advance for the help.

• Why would games be different than non game software? – Vaillancourt Jul 9 at 11:48
• @Vaillancourt harder real time constraints that sometimes make the programmer sacrifice certain luxuries such as readability for optimization – Ryoku Jul 9 at 11:50
• Have you encountered a problem in your game project where your current, readable code is not sufficiently optimized for your needs? Since optimization is so sensitive to the specifics of each situation, we're likely to be able to give you better advice if you show that particular case, rather than asking about "standard practice". The kind of sacrifice you're describing is often the exception to the standard, in places where our performance budget forces us to do something we might normally not. – DMGregory Jul 9 at 12:30
• This is an industry where we can't even agree on what a "game" is, or what job a "game designer" does. It wouldn't surprise me if you can find both header declaration conventions in common use at different studios. So asking "what do games usually do?" is generally not as useful a question as it might seem. What you really need to know is "what should my game do?" and do answer that, we'll ask you "what problem are you trying to solve?" - is the way you've been going about it so far impacting your runtime performance or iteration speed in some specific way we can help you solve? – DMGregory Jul 9 at 13:42
• Every application with a tight processing time budget will have the same problem. So your question should belong to StackOverflow. However, you might be interested in this question, this question (see the second answer) and this question – wychmaster Jul 9 at 14:06

This means that developers have to find the right balance between time it takes to produce a game (including a decent compile time -- developer's time == money) and how smooth it plays on the hardware (rightly optimized).