本文介绍了“死代码"与“死代码"之间有什么区别?和“无法访问的代码"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这些术语是同义词,但是MISRA中有关无效代码的注释表明这是错误的?有什么不同?一个是另一个的子集吗?

I thought those terms where synonymous, but a note in MISRA regarding dead code indicates this to be wrong? What's the difference? Is one a subset of the other?

推荐答案

无效代码-已执行但冗余的代码,要么从不使用结果,要么不向程序的其余部分添加任何内容.浪费CPU性能.

Dead code - code that is executed but redundant, either the results were never used or adds nothing to the rest of the program. Wastes CPU performance.

function(){
    // dead code since it's calculated but not saved or used anywhere
    a + b;
}

无法访问的代码-不管逻辑流程如何,都永远不会到达的代码.区别在于它没有执行.

Unreachable code - code that will never be reached regardless of logic flow. Difference is it's not executed.

function(){
    return x;

    // unreachable since returned
    a = b + c;
}

这篇关于“死代码"与“死代码"之间有什么区别?和“无法访问的代码"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 16:14