Questions About *.inl files

Started by
6 comments, last by jpetrie 17 years, 6 months ago
hello there! I want to ask some stuff about *.inl files It is said that you place there all the inline functions of a class. But how a simple file extension could change the compilation? I place my inline functions in *.cpp file. or *.hpp file and i get the same results! what is the difference if i place them in a *.inl file? If there is some difference.. in which compilers the inl files makes the difference? I want my code to compile at both MSVC++ 2005 and GCC (G++ actualy) for the Linux Port. And a final question.. Can I have the class definition in an *.h file, the inline class funtions definitions in an *.inl file and the rest class function definitions in a *.cpp file? thanks for your time!
Advertisement
There is no difference. The reason people use .inl is because it is the (unofficially) recognised way of saying "I have a lot of inline functions and I'm keeping them seperate from the class definition in the header file". It helps keep the class definition and implementation seperate.

The only files that the extension matters are .c and .cpp (which tell the compiler to compile the code contained in those files as either C or C++, although this can be overridden with compiler switches). Everything else can be named whatever the hell you want.

I personally use .cpp, .hpp (C++ headers) and .inl, but I could use .cpp, .foo and .bar if I really wanted too.
And...

Quote:Original post by Unreal
And a final question.. Can I have the class definition in an *.h file, the inline class funtions definitions in an *.inl file and the rest class function definitions in a *.cpp file?


Yes. :)
--== discman1028 ==--
Quote:
But how a simple file extension could change the compilation?
I place my inline functions in *.cpp file. or *.hpp file and i get the same results! what is the difference if i place them in a *.inl file?


When you place your inline functions in a .cpp file, they are not inline any more. The definition of an inline function must be available to every translation unit.

.h and .inl files never get compiled (and should not be!). They are pasted into your .cpp files via the preprocessor (#include); generally people will #include "foo.inl" in "foo.h" (because the aforementioned rule must be satisfied).
Oh, those inline functions in a .cpp file can still be inline, they just won't be available to the other .cpp files, I guess. Or if they are, then they won't be inline from there. I don't know how intelligent a compiler is on this issue. I know some will do link-time optimisations that may help here. Best not to rely upon it, however.
I just include the .inl file after class declaration in the .h file and it works :D
thank all of you guys! :D
Its also common to setup the project so they are only actually included as headers in release mode, so in debug mode you have the conveinence of treating them as CPP files.
Quote:
Its also common to setup the project so they are only actually included as headers in release mode, so in debug mode you have the conveinence of treating them as CPP files.


I don't understand. You don't get any benefit from this (not to mention it might be a pain to set up and maintain depending on what is actually in those files -- and in some cases won't work at all).

This topic is closed to new replies.

Advertisement