Avoiding unused variables warnings when using assert() in a Release build

前端 未结 16 1832
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 09:10

Sometimes a local variable is used for the sole purpose of checking it in an assert(), like so -

int Result = Func();
assert( Result == 1 );
<
16条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 09:33

    This is a bad use of assert, IMHO. Assert is not meant as an error reporting tool, it's meant to assert preconditions. If Result is not used elsewhere, it's not a precondition.

提交回复
热议问题