Sign in to follow this  

Questions About *.inl files

This topic is 4086 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

This topic is 4086 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this