if or #if(preprocessor)

Hi everyone,
I would like to ask that which of the following make the program fastest
if or #if(preprocessor)

Briefly, my question is that which one provide a program to be compiled or executed faster than the program done with other statement




Answer this question

if or #if(preprocessor)

  • Gideon Schlen

    The main point of all of this is that if and #if have very different goals. The point of an "if" is to provide a way to dynamically change the execution path at runtime. Whereas the "#if" provides a way to create different versions of the same code-base. For example, you might have a demo version and a retail version. The retail version has all the normal features. The demo version might have some additional code to pause the splash screen for some period of time.

  • adtjr51

    Note also, that if the expression yields a constant at compile time, then if() will be handled at compile-time, and IL will only be produced to the used path. IOW,

    #if false
    //// Some Code
    #else
    // Some More Code
    #endif

    and

    if (false)
    {
    // Some Code
    }
    else
    {
    // Some More Code
    }

    would generate identical assemblies. The only difference, is that the code in the false half of the if() must be syntactically correct or the compile will fail. The false half of the #if does not need to be compilable code.



  • Brent Yokota

    #if is processed before the code is compile. With this statment you cannot have "dynamic" comparision, your variable need to be defined before and is considered constant.

    #if is faster than "if" but they are completely different in their usage.



  • Johnfegkmx36k

    Oh, thanks very much again.
    It is the answer that I wanted to hear.

    Best wishes,
    Mert


  • Patrick Darragh

    Thanks very much for your reply...


  • if or #if(preprocessor)