Note that there are some explanatory texts on larger screens.

plurals
  1. POGarbage from other linking units
    primarykey
    data
    text
    <p>I asked myself the following question, when I was discussing <a href="https://stackoverflow.com/questions/4813947/how-can-i-know-which-parts-in-the-code-are-never-used/4814564#4814564">this</a> topic .</p> <p>Are there cases when some unused code from translation units will link to final executable code (in release mode of course) for popular compilers like GCC and VC++?</p> <p>For example suppose we have 2 compilation units:</p> <pre><code>//A.hpp //Here are declarations of some classes, functions, extern variables etc. </code></pre> <p>And source file</p> <pre><code>//A.cpp //defination of A.hpp declarations </code></pre> <p>And finally main</p> <pre><code>//main.cpp //including A.hpp library #include "A.hpp" //here we will use some stuff from A.hpp library, but not everything </code></pre> <p>My question is. What if in main.cpp not all the stuff from A.hpp is used? Will the linker remove all unused code, or there are some cases, when some unused code can link with executable file?</p> <p>Edit: I'm interested in G++ and VC++ linkers.</p> <p>Edit: Of course I mean in release mode.</p> <p><strong>Edit: I'm starting bounty for this question to get good and full answer. I'm expecting answer, which will explain in which cases g++ and VC++ linkers are linking junk and what kind of code they are able to remove from executable file(unneeded functions, unneeded global variables, unneeded class definitions, etc...) and why aren't they able to remove some kind of unneeded stuff.</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload