Harold Kraus

do-while-zero construct & MISRA Rule 19.4

Discussion created by Harold Kraus on Nov 15, 2010
Latest reply on Nov 30, 2010 by Daniel Lundin

 [WRT: CodeWarrior IDE 5.9.0 / Target S12X]

 

I am trying to comply with MISRA Rule 19.4, specifically the requirement that the do-while-zero construct is “the only permitted mechanism for having complete statements in a macro body.”

 

But, when I compile

do{<stuff>}while (0);

the compiler reasonably gives the message “C4001: Condition always false”.

 

Is there a way to use the do-while-zero construct without this nuisance message but without generally disabling the C4001 message, e.g., #pragma MESSAGE DISABLE C4001?          

 

Mind you, for compliance reasons I must have traceability between object and source code (i.e., no optimizations that mangle or obfuscate the object code).  Also, it would be nice to not have any branch that is always false or always true in the object code.

Outcomes