Overhead in unused code

前端 未结 4 658
时光取名叫无心
时光取名叫无心 2021-01-02 01:29

I am wondering what the overhead is of having unused functions in your code.

Say for example you have some debug logging, and you then give most of your objects a To

4条回答
  •  情深已故
    2021-01-02 01:55

    It depends on the compiler and, I guess, optimization level.

    G++ and MSVC++ remove unused inline functions but keep unused non-inline functions. For instance, you use only a small fraction of the STL in a normal program. All unused functions get removed, because they're defined as inline.

    GCC on the other hand keeps all functions, even unused inline ones.

    Answer to your other question: if a function is somehow defined in multiple compilation units, the linker will frown and refuse to link, unless if it is defined as inline.

提交回复
热议问题