Simple ways to disable parts of code

后端 未结 14 1131
误落风尘
误落风尘 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:23

    1 ? foo() : bar();
    

    This executes foo(). Change the 1 to a 0 to execute bar() instead.

    Unlike the suggestions involving preprocessor directives or comments, both possible branches are compiled, so you get the full benefit of the compiler's syntax checking.

提交回复
热议问题