When I include some functions from the header file in the C ++ program, copy the entire header file code into the last executable Or machine code is generated only for specific work. For example, if I type from std :: sort
to algorithm>
In the header C ++, call the machine code only for the sort () function or the entire & lt; Algorithm & gt;
header file.
I think the same question exists somewhere on the stack overflow, but I have tried my best to find it (I noticed it once but lost the link). If you can talk to me, then it will be wonderful
You got two specific issues here
- Header files handled by preprocessor
- Selective linking of code by C ++ Linker
header files
These codes are copied only by the preprocessor in the word-copy include
s to all the code of algorithm
to .pppp
F You have been copied to the URL when you have #include & lt; Algorithm & gt;
Featured Linking
Most modern linkers will not link to tasks that are not being called in your application. To wit. Type a function foo
and never call it - its code will not be executable so if you select #include & lt; Algorithm & gt;
and only use sort
, so what happens here:
- The preprocessor shows the entire
algorithm
- You can only
sort
- analyze this link and add only the
source of the sort
class Since you are using it (otherwise the compiler will not create it), the linker also places it in the executable.- code> ( And this calls, if any) code of executable other algorithms is not being added
He said, C ++ templates make this case a bit more complicated. This is a complex issue to explain, but in a nutshell - templates are expanded by all types of compilers, which you are actually using. So if the
vector
is theint
andvector
ofstring
, then the compiler will generate two copies in your code < Code for the code> vector - code> ( And this calls, if any) code of executable other algorithms is not being added
Comments
Post a Comment