When you include a header file, does it always include the whole thing, or only the parts that are used?
Printable View
When you include a header file, does it always include the whole thing, or only the parts that are used?
The entire thing is included. (Assuming you aren't doing something fancy with #defines, but other than that, yes.)
Quzah.
I think thats kind of stupid... it'd be more memory efficient not to... but it'd take longer to compile I guess
I was thinking of posting this question for a long time.Instead of starting a new thread,I will ask it here itself.
Y is it advised to use header files for classes instead of making them inline?I mean,the compiler will read the whole thing in both the cases,isn't it?
(Hey! Guess wat!This is my 50th post!)
You post count says 49...
Anyway: header files only contain declarations, and those don't need memory. The compiler always compiles the whole header file, but that doesn't make for memory consumption.
It is the linker that is responsible for ignoring unused functions and variables. Most linkers do it.
You mean why not put it in the cpp files directly?Quote:
Y is it advised to use header files for classes instead of making them inline?
So that other cpp files can use it too of course.
"Y is it advised to use header files for classes instead of making them inline?I mean,the compiler will read the whole thing in both the cases,isn't it?"
It's my understanding that when a function is inlined, the compiler replaces every call to that function with the actual code, so for short functions, it can be more efficient to do that. At some point though, with longer functions and lots of calls, I assume the efficiency of inlining is lost and function calls are more efficient.
The inline keyword is only a recommendation though, it's up to the compiler if the function actually gets inlined.
But I don't think this "inline" is the inline he meant.