cmisrapc-lint

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


I am defining some macro - #define temporary inside code, which I have #undef after being used.

Is it not allowed to #undef MACRO?

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;

}

}

Observed warning:

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


Solution

  • Yes, MISRA Rule 20.5 says that #undef should not be used. It's an advisory rule.

    Rationale:
    The use of #undef can make it unclear which macros exist at a particular point within a translation unit.