Search code examples
c++optimizationintelicc

Do intel C++ compiler optimize out functions that have never been called in the codes?


Just some opitmization considerations:

Does anyone know it for sure whether intel C++ compiler (such as ICC 13.0, and of cause, compiled with some optimzation options like /O3 etc) will automatically optimize out any unused/uncalled struct/class/functions/variables in the codes like examplefun() below:

         //...defining examplefunc()....//

         const int a=0;
         if (a>0) 
            int b=examplefunc();

Solution

  • The compiler does not usually optimize out unused functions unless they are static and, therefore, only accessible within a specific module. However, the linker might dead strip the function if linking is done at the function level and not the module level.

    You can check the assembly output, linker map, or use something like objdump to check if the function was included in the linked binary.