倚天杖
我发现它在经常涉及错误检测等操作的一系列动作中最有用。if ((rc = first_check(arg1, arg2)) != 0){ report error based on rc}else if ((rc = second_check(arg2, arg3)) != 0){ report error based on new rc}else if ((rc = third_check(arg3, arg4)) != 0){ report error based on new rc}else{ do what you really wanted to do}备选方案(不在条件中使用分配)是:rc = first_check(arg1, arg2);if (rc != 0){ report error based on rc}else{ rc = second_check(arg2, arg3); if (rc != 0) { report error based on new rc } else { rc = third_check(arg3, arg4); if (rc != 0) { report error based on new rc } else { do what you really wanted to do } }}使用长时间的错误检查,替代方法可以在页面的RHS之外运行,而有条件分配版本则不能这样做。错误检查也可能是“行动” - ,,first_action() -当然,而不是仅仅检查。即,可以在功能正在管理的过程中检查它们。(在我使用的代码中,大多数情况下,这些功能都是基于前提条件检查,或者功能正常工作所需的内存分配,或者类似的方式)。second_action()third_action()