Source: Gimpel Software Blog

Gimpel Software Blog From the Support Files - Macro Suppression Variations

A programmer recently wrote in with an example along the lines of the following:extern volatile int i;#define A (i > 4)void f(int j) { if ( j && A ) { /* do something */ }}Because of the volatile qualifier on i, Lint produces a MISRA diagnostic about side-effects on the right hand side of the && operator. The programmer was quite content to use a ‑emacro(960,A) to suppress this diagnostic but noticed the option did not work when the macro was placed in parentheses:extern volatile int i;#define A (i > 4)void f(int j) { if ( j && (A) ) { // diagnostic still issued /* do something */ }}The reason this didn't work, and the solution that does, deserves some explanation. The implementation of the ‑emacro(#, symbol) option causes the definition of the given macro to be surrounded by lint comments that issue a ‑save ‑e# and a ‑restore. For example, the if statement above would be transformed to:if ( j && (/*lint -save -e960 */ i > 4 /*lint -restore */) )The -restore option is processed before the ")" of "(A)" is processed. As such, the message is no longer suppressed by the time Lint analyzes "(A)" for the presence of side-effects. The solution is to use "‑‑emacro((960),A)". Options of the form "‑‑emacro((#), symbol, ...)" suppress messages matching the message # for the entire expression for each of the macro symbols given. The macros are expected to be expressions (syntactically). In the given example, the option acts as if the following macro definition was provided for "A":if ( j && (/*lint --(e960) */ i > 4) )In case you are wondering, Lint does have a single '‑' form of this option: "‑emacro((#), symbol, ...)". This form inhibits messages matching the message # for the macro expansion given by the named symbol, instead of the entire expression in which said macro appears. Applied to our example, the macro definition would have been transformed to:if ( j && (/*lint -(e960) */ i > 4) )which would not work in this case for the same reason that the original ‑emacro(960,A) did not work.

Read full article »
Est. Annual Revenue
$100K-5.0M
Est. Employees
25-100
CEO Avatar

Founder

James F. Gimpel

CEO Approval Rating

90/100

Read more