simple inlining question

Started by
13 comments, last by Damocles 19 years, 11 months ago
If you get the free VC 7.1 compiler from MS and turn on whole program optimization then it can inline functions from .cpp files (if the optimizer decides it''s worthwhile). That happens outside your control though - you still can''t declare the function as inline in the .h and put the definition in the .cpp and use it from another translation unit without linker errors.

Game Programming Blog: www.mattnewport.com/blog

Advertisement
It''s actually possible to inline a function even if it''s only declared in a header-file, and defined in a source-file. All of this is highly dependant on compiler/linker/platform and I have no idea which systems support link-time inlining. If you want to see if your system supports link-time inlining write a simple test and check the assembly code.

Thinking that inlining can only happen at compile-time (implying that the actual implementing code must be available to all compilation units) is a fairly common mistaken; in fact inlining can happen at compile-time, link-time, install-time and run-time.

- Neophyte
quote:Original post by Wuntvor
But it should still recompile everything if you change anything.. There''s just no way around it, as others have pointed out already.


Hmm... not sure if you were refering to my earlier post or not, but as I set it up in will only recompile everything in release, because it''s not actually inlined in debug. Since so much work is actually done in debug it does provide a bit of compile time relief.
quote:
The problem is, if I keep the inlined functions in the header file, then any time I want to make minor changes to the functions, I will have to recompile 90% of the project which takes ages. If I can find a way to keep them in a seperate file then I only have to recompile that file.

The problem''s right here:
quote:
I maintain a globals.h header file that contains the declarations for all global variables and functions which then gets included in almost every new class/file.

Include only the things that you need. Sure it might be faster to just #include every header in one master header file in the short run, but in the long run it''s going to cause a lot of trouble, as you have already seen.

Ofcourse none of this should be necessary, as any modern language has compilation units, not header files. I don''t even use C or C++ anymore for the project specific code anymore; I either use python, or in the future I''ll use the lisp scripting module in the engine I plan on making.

The main reason C is still used is so that functions can be accessed from different languages; there''s no way to reliably interface to C++ code and be compiler independent due to name mangling.
This guy thinks inlining should be avoided. I believe him.
My stuff.Shameless promotion: FreePop: The GPL god-sim.

This topic is closed to new replies.

Advertisement