Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Visual Studio C++ compiler empty functions

Visual Studio C++ compiler empty functions

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studioquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    severin0
    wrote on last edited by
    #1

    Does anyone know if the Visual Studio C++ compiler optimizes to eliminate calls to functions with empty definitions (nothing between the curly braces denoting the function's body)? I am particularly interested in the 2010 and 2012 versions of the Visual Studio compiler. Thank you.

    Richard Andrew x64R D M 3 Replies Last reply
    0
    • S severin0

      Does anyone know if the Visual Studio C++ compiler optimizes to eliminate calls to functions with empty definitions (nothing between the curly braces denoting the function's body)? I am particularly interested in the 2010 and 2012 versions of the Visual Studio compiler. Thank you.

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      It would be easy enough for you to find this out for yourself. Create a small test program with such a function, and use Disassembly View to step through the code where the function is called. OTOH, these are the two optimizations that I do know about: 1. It combines functions that have identical definitions, and 2. It eliminates functions that are never called Both of these optimizations can be turned off in the Options dialog box.

      The difficult we do right away... ...the impossible takes slightly longer.

      1 Reply Last reply
      0
      • S severin0

        Does anyone know if the Visual Studio C++ compiler optimizes to eliminate calls to functions with empty definitions (nothing between the curly braces denoting the function's body)? I am particularly interested in the 2010 and 2012 versions of the Visual Studio compiler. Thank you.

        D Offline
        D Offline
        Daniel Pfeffer
        wrote on last edited by
        #3

        It depends on whether the method is virtual. It would theoretically be possible to eliminate all calls to empty non-virtual methods. A virtual method may be overridden by a derived class, so the compiler must perform the virtual call. (There may be some cases where the compiler can prove that the virtual call refers to the base class. In this case, the compiler could optimize the call away.) As Richard suggests, the best way to check this is to write a short test program.

        If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill

        1 Reply Last reply
        0
        • S severin0

          Does anyone know if the Visual Studio C++ compiler optimizes to eliminate calls to functions with empty definitions (nothing between the curly braces denoting the function's body)? I am particularly interested in the 2010 and 2012 versions of the Visual Studio compiler. Thank you.

          M Offline
          M Offline
          Maximilien
          wrote on last edited by
          #4

          Yes, the compiler will eliminate useless calls (maybe not in DEBUG mode, but surely in RELEASE mode). today's compiler are a lot more smarter than you can imagine. Is there a particular reason for this question?

          I'd rather be phishing!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups