PC-Lint代码静态检查之Warning 522:Highest operation ... ... lacks side-effects

    xiaoxiao2021-03-25  81

    编写代码时,经常用for循环来做延时,比如:

    void userDelay(void) { int16_t tempCnt; for(tempCnt=20;tempCnt>0;tempCnt--) { asm(" NOP "); } }

    但是,如果该函数被程序调用,利用PC-Lint做静态检查时,会报”Warning 522: Highest operation, function ‘userDelay’, lacks side-effects”。

    下面这段关于该警告的英文说明,看了半天也没看明白。

    网上找了半天,终于在一个论坛上找到了该问题的答案: 意思是说上面定义的延时函数“什么都没做”。也许这就是所谓的“缺少副作用”,后来发现,如果将上面定义的函数与其余程序发生交互(也就是产生了所谓的“副作用”),该警告就会消除,比如:

    int16_t cnt; void userDelay(void) { for(cnt=20;cnt>0;cnt--) { asm(" NOP "); } }

    或者,

    int16_t test; void userDelay(void) { int16_t tempCnt; for(tempCnt=20;tempCnt>0;tempCnt--) { asm(" NOP "); test = tempCnt; } }

    显然,后面这种交互会造成延时时间的不同。

    转载请注明原文地址: https://ju.6miu.com/read-16003.html

    最新回复(0)