Simple ways to disable parts of code

后端 未结 14 1133
误落风尘
误落风尘 2021-01-31 08:59

This isn\'t a typical question to solve a specific problem, it\'s rather a brain exercise, but I wonder if anyone has a solution.

In development we often need to disable

相关标签:
14条回答
  • 2021-01-31 09:24

    Well, if the code that needed to be disabled once or twice before finalizing, I prefer to use hotkeys provided by IDE to comment that code out, and later comment in. Yes, I need to select the code block first, but I prefer not to include one more debugging variable/preprocessor directive/if statement every time I need to disable a part of code. This happens to be most of the time.

    If, on the other hand, I need to repeatedly switch between 2 code blocks to find the right thing, then I use a if (0) / if (1) to disable/enable code block.

    [code block 1]
    

    Later

    if (0)
    {
        [code block 1]
    }
    else
    {
        [code block 2]
    }
    
    0 讨论(0)
  • 2021-01-31 09:27
    #if 0
    ...disabled code here
    #endif
    
    0 讨论(0)
提交回复
热议问题