Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

header files with multiple entries

Status
Not open for further replies.

mastermagrath

Technical User
May 21, 2004
28
0
0
US
Hi,

Something is confusing me with regard to function declarations in header files. If i include a header file with many different function declarations in my main module but only actually use one of the functions does this mean that all of the function definitions are eventually linked in or just the one i used.

Cheers
 
Actually, i've just tried compiling a program of mine after adding in a few dummy function declarations in the header file and it all compiled as usual......so i guess the answer is no! Does this mean that function declarations are purely for the compilers use and nothing to do with the linker/executable and hence dont effect the size of the executable?
 
I've noticed that template, function or class declarations don't matter until you try to use them.

I think the real question should be, if you have templates/classes/functions (with all the code, not just declarations) in your program, but they are never used, do they take up space in the final executable?
 
They will not be in the executeable if the compiler/linker can be sure they never are used. Which it normally can.

However if you're dealing with virtual methods it isn´t alway clear at compile/link time exactly what classes are instantiated (and consequently what methods are executed).
Thus those methods might be in the executeable even though they are never called.

/Per
[sub]
www.perfnurt.se[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top