不鼓励使用“#undef”:'ssCmd' [MISRA 2012 规则 20.5,咨询]

use of '#undef' is discouraged: 'ssCmd' [MISRA 2012 Rule 20.5, advisory]

我正在定义一些宏 - #define 临时内部代码,使用后我有 #undef

是否不允许#undefMACRO?

void c_cmd(unsinged char *com)
{ 

int abc = com[0];
int res = 0;

switch(abc)
{
    case 1:
             #define ssCmd                 com[2]  /* SRT or STP*/
             res = abc + ssCmd;     
             /* part of some functionality */          

             #undef ssCmd 
             break;

    default:
             break;

}

}

观察到的警告:

use of '#undef' is discouraged: 'ssCmd' [MISRA 2012 Rule 20.5, advisory]

是的,MISRA 规则 20.5 规定不应使用 #undef。这是一个建议规则。

#undef 通常不需要。当在代码中使用它时,它的使用可能会导致对宏的存在或意义的混淆。