Is there a way to get VS2008 to stop warning me about unreachable code?

前端 未结 8 1930
我在风中等你
我在风中等你 2021-02-05 02:04

I have a few config options in my application along the lines of

const bool ExecuteThis=true;
const bool ExecuteThat=false;

and then code that

8条回答
  •  别那么骄傲
    2021-02-05 02:25

    The fact that you have the constants declared in code tells me that you are recompiling your code with each release you do, you are not using "contants" sourced from your config file.

    So the solution is simple: - set the "constants" (flags) from values stored in your config file - use conditional compilation to control what is compiled, like this:

    #define ExecuteThis
    //#define ExecuteThat
    
    public void myFunction() {
    #if ExecuteThis
        DoThis();
    #endif
    #if ExecuteThat
        DoThat();
    #endif
    }
    

    Then when you recompile you just uncomment the correct #define statement to get the right bit of code compiled. There are one or two other ways to declare your conditional compilation flags, but this just gives you an example and somewhere to start.

提交回复
热议问题